Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

C Server - Java Client

 
Derek Drever
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to produce a java client to an existing server written in C. The server currently has several clients also written in C, and various messages have been defined (as C structures containing int and char[] etc) which pass between client and server via read/write calls.
I am having problems designing a solution, I could read the message as a byte[], but was unsure how to translate a sequence of bytes into an int for example (Big Endian or little Endian ?), I could translate a sequence of bytes representing a C null terminated string into a Java String easily enough but the whole mechanism would be quite slow for large volumes of data.
I also wondered if there were convenience classes (in the public domain) which could be used to read/write such messages from within a java program, I would have thought this sort of thing was quite common.
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading the socket as a byte[] array is exactly what you have to do. It probably won't be as slow as you might think, unless you are wanting to transfer gigabytes per hour.
You can check out http://jakarta.apache.org/poi/hssf/index.html (The POI HSSF project). This is a 100% Java application that reads and writes Microsoft Excel. It has utility classes which convert BigEndian, LittleEndian, dates, and Strings.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!