• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

C Server - Java Client

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic