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 ]
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().