UDP DatagramPacket sent between C (client) and Java (server)

Hi,
I have a problem sending a struct from C to Java UDP server.
In the C (client) program, the struct is defined as
typedef strurct dataType_s {
char name[52];
char add[52];
long x;
long y;
} dataType;
dataType data;
strcpy(data.name, "sun");
strcpy(data.add, "com");
data.x = 100;
data.y = 50;
sendto(sock, (struct dataType*)&dataType, sizeof(dataType), (struct sockaddr*)&dest, sizeof(dest))
In the Java server side, I have the following code.
byte[] buffer = new Byte[1024];
DatagramPacket packet = new DatagramPacket(buffer, 1024);
udpSock.receive(buffer);
byte[] data = buffer.getData();
String name = new String(data, 0, 52);
String add = new String(data, 52, 52);
String _xx = new String(data, 104, 4);
String _yy = new String(data, 108, 4);
Byte x = new Byte(xx.getBytes());
long x = _x.longValue();
Byte y = new Byte(yy.getBytes());
long y = _y.longValue();
I am having problem to read the contents of x and y above. The string name and add received by the server
are correct. However, I receive garbage value
for x (long) and y (long). In fact, I get expection
that I cannot create Byte x and Byte y as shown
above. Any idea of how to send a mixture of types
from C/C++ to Java server?
Thanks a lot.
Kelvin ([email protected])

sendto(sock, (struct dataType*)&dataType,
sizeof(dataType), (struct sockaddr*)&dest,
sizeof(dest))You have to check the alignment of your structs. You can't be sure that a long takes up four bytes. It can very well be 8 bytes or something else depending on your settings at compilation.
udpSock.receive(buffer);
byte[] data = buffer.getData();I suppose this is a typo, but of course you should use packet not buffer here.
>
Byte x = new Byte(xx.getBytes());
long x = _x.longValue();
Byte y = new Byte(yy.getBytes());
long y = _y.longValue();
in my opinion its easier to use a DataInputStream instead:
DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
int y = in.readInt();
Notice that a long in Java is 8 bytes. A C long corresponds to a Java int.
/Per-Arne

Similar Messages

  • Data transfer between C client and Java server

    Hello there
    I am working on a project where I have to develop a Client based on C and Server based on Java. The client can connect to Java server and it then sends a integer/string to Java server. But.. Java server unable to receive that and throws an IOException.
    I use write method to send the integer buffer to the socket.
    int out_buffer = 0;
    int *pbuf;
    pbuf = &out_buffer;
         if (write(acskfd, pbuf, 4)< 0){
                   syslog(LOG_ERR,"Write failed. %s(%d)", strerror(errno), errno);
                   printf("\tCLIENT:\tWrite failed\n");
                   exit(1);
    In Java, i use DatainputStream and readnInt method to read the integer from the stream.
    cl_sock = socket_out.accept();
    DataInputStream sInput =new DataInputStream(cl_sock.getInputStream()) ;
    int cmd = sInput.readInt();
    Am I missing someting.. Any suggestions would be really really helpful.
    Thanks
    Ithaca
    PS: I running both programs in the same machine.
    In C part, I also use host to network byte order conversion (serv_addr.sin_port = htons(portno).

    I would suggest writing a Java client to perform the same tasks as the C client.
    Then if the Java client does, or does not work this can help dteremine which end is at fault.
    Are you flushing your data from the client?

  • Difference between oracle client and oracle server?

    Hi,
    could any one please tell me the difference between these things?
    1.)oracle client and oracle server
    2.) installtion of oracle client and oracle server
    Thanks in advance.

    Take a look at the general client - server computing model, described e.g. in this wiki.
    edit:
    corrected bad link
    Message was edited by:
    orafad

  • NFS problem between RedHat Client and Solaris Server

    Hi all, we are experiencing a problem between a RedHat client and a Solaris 10 server. For the purposes of this post, I'll call the Redhat client server A and the Solaris 10 server B.
    Server B is exporting a filesystem that server A is trying to mount. Server A can successfully mount the exported file system, however, strange things are happening. If I change to the exported mount point on server A and create a file, the file is owned by nobody:nobody, not the user that created the file.
    A look at the file on server B shows the file has the correct UID and GID (ie the UID & GID of server A).
    The fstab file on server A looks like this:
    serverB:/data /data nfs4 rsize=32768,wsize=32768,hard,nointr,rw,bg,actimeo=0,timeo=300,suid 0 0
    Does anyone have a explanation for this?
    NB: There is a firewall between server A and server B. A firewall rule is in place to allow traffic between the two servers on port 2049
    Stewart

    Hi
    If I change to the exported mount point on server A and create a file, the file is owned by nobody:nobody, not the user that created the file.On a NFS share, for security reasons, you normally dont have root provileges.
    A file createt as root user will be mapped to nobody:nobody.
    The behaviour you see is correct.
    If you want the file to be createt as root, you have to export the filesystem with -o ro,anon=0
    NFSv3 will be blocked by your firewall.
    Franco

  • Error 2032 in communication between Flex Client and WCF

    Hi All,
    I'm trying to establish communication between Flex Client
    and WCF service.
    WCF service accepts gZip compressed data and returns gZip
    compressed results.
    So I used Flex ByteArray.compress() and
    ByteArray.uncompress() for this purpose. However, it throws error
    2032.
    The gZip compression/decompression uses MemoryStream class in
    C#. Based on my previous experience, memory stream communication
    between Flex and C# gives erro 2032.
    Is there a work around for this?
    Thanks,
    Vishal

    I read some thread in the forum, and found somebody had the similar problem with me. Just want to know how to settle this problem.
    In the client/server program. Client is a JAVA program and Server a
    VC++ program. The connection works, and the problem appears after some time. The Client sends a lots of requests to Serverm, the server seems receive nothing. But at the same time, the server is able to send messages to Client. The Client also can get the messages and handle them. Don't understand why there this problem and why it appears when it wants.
    The client is a Win2k platorm with JDK1.3.1 and the server is also a Win2K platform with VC++ 6.0.
    In the Client, using:
    inputFromServer = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    outputToServer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
    Hope can get your help.

  • Component that implements encryption solution between the browser and Java

    I need a Component that implements encryption solution between the browser and Java tier.
    I am a java programmer and have really limited knowledge about cryptography. I work on JSF . I am basically looking to build a component that will ensure that the password entered by the user in the login page of the browser is properly encrypted using Java script and then we should be able to decrypt it in the Java Tier.
    Basically, I think we need a public-private key system. We send the public key to the browser and use it with JavaScript to encrypt the key and we hold the private key on the server to decrypt it.
    If some one can help me with this it would be very helpful. Or if anyone can point me to some resource that does this kind of thing I shall be obliged.

    Can't use HTTPs as many of our existing customers
    that run on intranet do not use HTTPs.Is there really a technical reason that your clients cannot use HTTPS? If so, what is it and why would your homebrew re-implementation of the same technology be acceptable instead?

  • Difference between instant client and full oracle client

    Everyone,
    I had read the below lines from a goldengate pdf. Someone please explain me what is the difference between instant client and full oracle client?
    What is the use of XDK libraries.?
    " The full Oracle client must be used with GoldenGate so that the GoldenGate programs
    have access to the Oracle XDK libraries. Do not use Oracle Instant Client, which lacks
    those libraries. You can download the full client from Oracle’s website."
    Regards,
    SAKTHi

    The dealio is this:
    When you install client software, you have several options as to the degree of what you get/install. The big chicken dinner is administrator, so you get all kinds of extra features, add-ons, libraries, utilities, etc. At the hard candy Christmas end is instant client, and that has just enough functionality to, as you may surmise by now, connect a client and that's about it. Various libraries have functionality built in to do whatever extra is required. An example is FAN, or fast application notification, used in Data Guard failover. A FAN API (Java) will detect a failover and re-direct a client connection to the new primary. What GG uses XDK for (specifically) isn't of importance to a user, just the fact that it is available for connecting to Oracle is.

  • Connection between SDM client and server is broken

    Dear All,
    First of all this is what I have
    -NW04 SPS 17
    -NWDS Version: 7.0.09 Build id: 200608262203
    -using VPN connection
    -telnet on port 57018 is succesfull
    I can login to SDM server (from NWDS and from SDM GUI) I can see the state of SDM(green light), restart it, can navigate through tabs in GUI, but every time I am trying to deploy an ear i have this error:
    Deployment exception : Filetransfer failed: Error received from server: Connection between SDM client and server is broken
    Inner exception was :
    Filetransfer failed: Error received from server: Connection between SDM client and server is broken
    I have already read a lot of topics,blogs,notes but didn't find the solution.
    Can anybody help me?
    Best Regards

    Having same issue. Nothing helped so far... Using NWDS 7.0 SP18.
    I have turned SDM tracing on and this is what I see on client side after sending first data package:
    com.sap.sdm.is.cs.cmd.client.impl.CmdClientImpl: debug "20120224140253 0280/17 Client: finished sending string part"
    com.sap.sdm.is.cs.cmd.client.impl.CmdClientImpl: debug "20120224140253 0280/0 Client: receive String part from Server"
    com.sap.sdm.is.cs.cmd.client.impl.CmdClientImpl.receiveFromServer(NetComm ..): Entering method
    com.sap.bc.cts.tp.net.NetComm.receive(): Entering method
    com.sap.bc.cts.tp.net.NetComm: debug "Method "receive(char[])" could not read all requested bytes. There are still 12 bytes to read"
    com.sap.bc.cts.tp.net.NetComm: debug "Caught IOException during read of header bytes (-1,          43):Connection reset"
    com.sap.bc.cts.tp.net.NetComm: debug "  throwing IOException(net.id_000001)"
    com.sap.bc.cts.tp.net.NetComm.receive(): Exiting method
    com.sap.sdm.is.cs.cmd.client.impl.CmdClientImpl: Exiting method
    com.sap.sdm.is.cs.cmd.client.impl.CmdClientImpl: debug "20120224140253 0281/1 Client: connection was broken"
    com.sap.sdm.is.cs.cmd.client.impl.CmdClientImpl: Exiting method
    com.sap.sdm.is.cs.cmd.client.impl.CmdClientImpl: debug "20120224140253 0281/0 Client: finshed sendAndReceive"
    com.sap.sdm.is.cs.cmd.client.impl.CmdClientImpl: Exiting method
    My connection on server is still active so I have to restart SDM server to reset and try it again.
    Anyone have idea whats happening?
    Edited by: skyrma on Feb 24, 2012 2:46 PM
    Edited by: skyrma on Feb 24, 2012 2:47 PM
    Edited by: skyrma on Feb 24, 2012 2:47 PM

  • Diff between Thin client and Rich client

    Hi Everyone,
              Can someone give me a clear picture of the what is the diff between Thin client and Rich client.
    Thanks,
    Krishna

    Hi,
    thick client (rich client) has/stores all the data inside itself
    so it can do application processing without the server with data
    thin client uses resources from host computer (from server)
    and wihtout that you are not able to work with that kind of client
    does that answer your question ?
    Regards,
    michal

  • Daughter's iPod Touch receiving texts sent between my wife and I

    My daughter's iPod Touch is receiving texts sent between my wife and I.  I understand that I can manually disable this on the iPod Touch, but she could feasibly re-enable this and spy on us.  Is this correct?  If so, this is a huge problem for everything from discussing surprise birthday plans, Christmas presents, to sending "intimate" messages to one another.
    How do I handle this centrally and permanently prevent her from seeing messages that my wife and I send back and forth?

    Your daughter needs her own Apple ID for iMessage, FaceTime & iCloud.
    The Apple ID needs to be a verified email address. Once you have an email address, that can be verified, go here & create the ID:
    https://appleid.apple.com/cgi-bin/WebObjects/MyAppleId.woa/wa/createAppleId
    Then on her phone, turn off Contacts, Calendars, etc. for iCloud. You'll be prompted to keep the data or delete it from the phone, then turn off iMessage, FaceTime & delete the iCloud account...Settings>iCloud...scroll down...delete account. Then, setup iCloud using the new Apple ID, turn on iMessage & Facetime.
    This will have no affect on the ID you both share for iTunes content, & you can continue to do so.

  • Passing variables between data tag and Java

    Hello all,
    I have a question about using variables between data tag and java.
    Let me explain.
    I would like to populate variable "Test" with
    the information returned by jbo data tag library.
    <code>
    <% String Test = "%><jbo:ShowValue datasource="ds" dataitem="Cod" /><%";%>
    or
    <% String Test = "<jbo:ShowValue datasource="ds" dataitem="Cod" />";%>
    </code>
    This code did not work.
    Some suggestions
    Thanks
    Humberto
    null

    Humberto,
    I'm afraid I do not know the specific answer
    to your question (perhaps Juan the Data Tag
    Wizard will reply ;-). I vaguely recall
    struggling with teh same issue when I was
    playing with the tags for a demo. Here
    is a hack-around lifted from my demo
    that might help:
    <jbo:Row id="privRow" action="CURRENT" datasource="privileges" />
    <%
    String privName = (String)privRow.getAttribute("Privilegename");
    %>
    In other words, I ended up using the Row
    tag to get a local Java variable bound to the
    row instance and then used its methods
    to extract the value. I presume the class
    of the row instance is oracle.jbo.Row
    and you can lookup its supported methods
    in the reference doc.
    I'd be interested to hear if their is a more
    elegant way - the one suggested above is
    pretty tedious.
    Regards,
    Bill
    ----

  • When I send a document for signature, two emails are sent to my client and myself.  How do I make sure only one is sent?

    When I send a document for signature, two emails are sent to my client and myself. How do I make sure only one is sent?

    Hi Mark,
    I checked your account at the backend and found many transactions sent out.
    In order to narrow down the issue and search we need to know the specific transaction detail for which you faced this issue.
    1. Signers email address
    2. Senders email address
    3.Name of the document
    4. Date it was sent.
    Do not post the information here. Send me a private message
    Also let me know which 2 mails did you receive? Could you please share the subject line for the same.
    Regards,
    Rave

  • Difference between Golden Client and Master Client

    Dear,
    What is the Difference between Golden Client and Master Client?
    Thanx & Regards,
    Mohammad Nabi,
    [email protected]

    Golden Client is similar or is the the same as Development Client, which should not be used for testing.
    Master Client ???
    Note on SAP Landscape:
    Landscape is like a server system or like a layout of the servers or some may even call it the architecture of the server’s viz. SAP is divided into three different landscape DEV, QAS and PROD.
    -  DEV would have multiple clients for ex: 190- Sandbox, 100- Golden, 180- Unit Test.
    -  QAS may again have multiple clients for ex: 300- Integration Test, 700 to 710 Training.
    -  PROD may have something like a 200 Production.
    These names and numbers are the implementer's discreet on how they want it or they have been using in their previous implementations or how is the client's business scenario. 
    Now whatever you do in the Sandbox doesn't affect the other servers or clients. Whenever you think you are satisfied with your configuration and you think you can use it moving forward, you RE-DO it in the golden client (remember, this is a very neat and clean client and you cannot use it for rough usage). As you re-do everything that you had thought was important and usable, you get a transport request pop up upon saving every time. You save it under a transport request and give your description to it. Thus the configuration is transported to the Unit Test client (180 in this example). 
    You don't run any transaction or even use the SAP Easy Access screen on the 100 (golden) client. This is a configuration only client. Now upon a successful transport by the Basis guy, you have all the configuration in the Testing client, just as it is in the Golden client. The configuration remains in sync between these two clients. 
    But in the Testing client you can not even access SPRO  (Display IMG) screen. It's a transaction only client where you perform the unit test. Upon a satisfactory unit test, you move the good configuration to the next SERVER (DEV). The incorrect or unsatisfactory configuration is corrected in Golden (may again as well be practised in the sandbox prior to Golden) and accordingly transported back to 180 (Unit Test) until the unit test affected by that particular config is satisfactory. 
    The Golden client remains the 'database' (if you wanna call it that) or you may rather call it the 'ultimate' reference client for all the good, complete and final configuration that is being used in the implementation.
    In summary:
    Landscape : is the arrangement for the servers
    IDES : is purely for education purpose and is NOT INCLUDED in the landscape.
    DEVELOPMENT ---> QUALITY -
    > PRODUCTION
    DEVELOPMENT : is where the the consultants do the customization as per the company's requirement.
    QUALITY : is where the core team members and other members test the customization.
    PRODUCTION : is where the live data of the company is recorded.
    A request will flow from Dev->Qual->Prod and not backwards.
    1. Sandbox server: In the initial stages of any implementation project, You are given a sandbox server where you do all the configuration/customization as per the companies business process.
    2. Development Server: - Once the BBP gets signed off, the configuration is done is development server and saved in workbench requests, to be transported to Production server.
    3. Production Server: This is the last/ most refined client where the user will work after project GO LIVE. Any changes/ new development is done is development client and the request is transported to production.
    These three are landscape of any Company. They organized their office in these three way. Developer develops the program in Development server and then transport it to test server. In testing server tester check/test the program and then transport it to Production Server. Later it will deploy to client from production server.
    Presentaion Server- Where SAP GUI has.
    Application Server - Where SAP Installed.
    Database Server - Where Database installed.
    Regards,
    Rajesh Banka
    Reward points if helpful

  • Difference between native client and workstation client.

    hi,
    I am confused with the difference between native client and workstation client.In
    some docs,it is said that native client is one which run on the same system as
    the server,in other it is said running on other machine in the same domain.So
    what about workstation client?So can anyone please helpme out in knowing this
    difference?

    subhash wrote:
    hi,
    I am confused with the difference between native client and workstation client.In
    some docs,it is said that native client is one which run on the same system as
    the server,in other it is said running on other machine in the same domain.So
    what about workstation client?So can anyone please helpme out in knowing this
    difference?The simple answer is that /WS clients are compiled with the -w option.
    The complicated answer has to do with how the client connects to Tuxedo during the
    tpinit(), and all subsequent traffic. A Tuxedo Domain (instance) has a Bulletin
    Board, which is a chunk of shared memory with all kinds of information about Servers
    and Clients. A Native Client, since it is running on the same machine that the
    Bulletin Board exists on, can directly access the shared memory. However, /WS client
    (also called a remote client) cannot access this shared memory. Instead, we have the
    WSL server to make connections with, and then WSH processes that access the Bulletin
    Board on behalf of the remote client.
    So Native Clients run on the same machine as the Servers and where the Bulletin Board
    is located, and have direct access to shared memory and other IPCs. Workstation
    Clients/WS Client/Remote Clients (all the same thing) cannot access IPCs and have the
    WSH do it on their behalf.
    In NT, the Tuxedo IPC Service mimics Unix IPCs, and so all the above is still true.
    Brian Douglass
    Transaction Processing Solutions, Inc.
    8555 W. Sahara
    Suite 112
    Las Vegas, NV 89117
    Voice: 702-254-5485
    Fax: 702-254-9449
    e-mail: [email protected]
    [briand.vcf]

  • XMLsocket and java server

    Hi
    I would like to developp a client which connects on a java
    server.
    When i run my program on my developement computer, it works
    (maybe because the server and the flex application are on the same
    machine.)
    But when i want to run the flex application from another
    computer I can't manage to get connected...
    First question : is it possible to connect flex appli to java
    server through internet or network
    Example
    123.2.2.2:18000 this is the (false) ip on my javaserver (the
    port 18000 is open)
    and I want to connect to it with a flex application from
    another computer.
    Thank you for you help
    Nicolas

    Hi,
    I discovered your topic too late so I made a duplicate topic
    about socket and java server.
    I spend quite a long time trying to solve this problem and I
    don't have the solution !
    It should be a common question so I guess the answer is so
    easy than I can't see it !!
    TechNote seams to say that you have to put the
    crossdomain.xml file on the root of the (html) server and not on
    the server where the flash file is.
    The problem is that I don't have or need a web server as my
    java server is doing the job. So I don't think it is the answer.
    Did you find the answer ?
    THX
    Jean-Yves

Maybe you are looking for

  • Sample  PL/SQL Portlet Source Code for Oracle Portal 9ias

    Hi, I'm a newbie of Oracle Portal technology, and I have a problem: I would create a PL/SQL portlet that realizes the following functions: 1) Retrieve the username of the portal user logged from WWCTX_API.GET_USER function. 2) Insert into an oracle d

  • Default Mail app not working with yahoo mail. Won't update.

    Default Maill app not working with Yahoo Mail. It stopped working the other day. I tried everything but it wouldn't update new mail. The yahoo account itself is fine because I can see new mail on Yahoo or a yahoo app. I tried deleting the account and

  • Thunderbolt to Firewire 800 external drive problems

    I recently upgraded from a MacBook Pro 17" early 2011 to a MacBook Pro Retina 15" (early 2013).  I have a Drobo and two Seagate 4TB external drives, all connected via Firewire 800.  So, I added a Thunderbolt to Firewire 800 adapter and, it seemed, li

  • Problem is Module pool custom F4 help

    In module pool selection screen . I have defined vendor field as a select option and attached a custom search help to it . Now the problem is that when i press F4 on that field and select a value from the help , that value is not populated in the inp

  • ChoiceBox and ComboBox

    Hi all, I am using Scene Builder and I have two questions about Choice Box. 1) What is the difference between ChoiceBox and ComboBox? It seems both have same features and functionalities 2) How to change default item1, item2, etc, font style and size