views:

247

answers:

3

What is the best way to pass data between a C server to a Java applet? Currently it's done by using a buffer and copying bytes to it using memcpy, but if the object ever changes I have to hunt down every instance of where it's being sent to the applet and have it changed.

Is there a better way to pass object to java? How would you do it?

Edit for clarification: It is going from the C server to the Java applet only, there is no java servlet. The only thing the Applet passes to the C server is a hex number signaling an action to be taken

+1  A: 

I would have opened a socket connection between the two applications. You could serialize the object to an array of bytes and have the Java servlet deserialize it into a Java object with the same value. This way if the class definition changes, you only have to change the code in two places.

Bill the Lizard
+1  A: 

I would serialize the objects to either XML or google protobuf on the C side and have them deserialized on the applet side using a single deserializer. I.e. don't have more then one class that does the deserialization. Make user that you version the serialization and that the object that does the de-serialization throws an exception if the version it tries to read is not backward compatible. It would be a bad practice to have the serialization and deserialization all over the code.

eishay
That might not be a good solution if performance gets to be a problem. XML is not very space-efficient
Stephan Eggermont
Some of the users of the applet are on dialup, so it would be...
Malfist
+4  A: 

You might want to take a look at Protocol Buffers

They let you define structured data, then generate the code to read and write messages in any of the supported languages. The only catch is I think they only support C++ for now, though I know there was interest in straight C implementation.

Mark Renouf
It looks simple enough, the server can use C++ code, just it's currently written in all C, I intend to change that though.
Malfist