Wonderer said:
we all know that you can send structs between C programs easily with
TCP/IP, but if u let a C server send a struct to a JAVA client, how will
the client be able to process the struct?
Just to clarify things on the C/C++ side. You're probably thinking of
casting a struct pointer to a char pointer, and then using sizeof to
determine the size of the struct and sending its in-memory
representation directly over a TCP socket. You should be aware that
this works reliably *only* if the following conditions are all
satisfied:
1) Both sides are running on the same operating system and hardware.
2) Both sides are compiled with the same compiler and version.
3) Both sides are compiled with the same flags/optimization level.
If you do this, you should find out the exact wire protocol and document
it, and clearly document that your struct trick works because it happens
to coincide with the documented wire protocol on a given platform,
compiler, version, and set of flags. Ideally, you'd document all of
those details so someone reading could reproduce your protocol. All
other clients that don't match that platform, compiler, version, or set
of compile options (including, of course, any Java clients) would need
to implement I/O over the stream using the documented wire protocol
rather than the struct trick.
As for how to do that, it involves DataInputStream and DataOutputStream
in Java (unless your protocol is little-endian, in which case Roedy's
web site has a little-endian version of those classes that will do what
you need). The standard socket routines along the lines of htonl() will
help in C, but the process is more involved.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation