Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Passing Structures of c to sockets of Java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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().
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic