my dog learned polymorphism*
The moose likes Sockets and Internet Protocols and the fly likes Passing Structures of c to sockets of Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Passing Structures of c to sockets of Java" Watch "Passing Structures of c to sockets of Java" New topic
Author

Passing Structures of c to sockets of Java

ManishB Joshi
Greenhorn

Joined: Jul 19, 2003
Posts: 2
I am currently working on java with c and also JNI layer i have specific problem as i m interested in passing certain structures of c from java sockets to my c server Example
Lets say we have two machine
Machine : A with Java as a client
Machine : B with C as a Server written in c
I m interested to pass some data which has a layout as defined in structures of C which needs to be passed across application. Can it be done without any Jni layer in between???
[ July 19, 2003: Message edited by: ManishB Joshi ]
[ July 19, 2003: Message edited by: ManishB Joshi ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

It can be done very easily if you have some control the format of the data on the C end. If you send things in "network byte order" (big-endian) and if the individual primitives don't have "packing holes" in between them, then you can use, e.g., DataInputStream to read the primitives. If, on the other hand, you have no control over the format -- perhaps it's little-endian, with holes -- then as long as the format is known, you can read data one byte at a time in Java and re-assemble the primitives using some bit-shifting and methods like Float.intBitsToFloat().


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing Structures of c to sockets of Java
 
Similar Threads
Best alternative to JNI for C/C++ code
debugging JNI application
NIO to implement the data reading/writing
Java application talking to web server
What is the 'host" in the .getByName() method?