My server and client are running on the same machine so I dont have endian issues etc. I need something that works on both vc++ and g++ and possibly the simplest way. What can I send the struct with?
Edit
struct Info
{
int** fields;
char** field_names;
};
You can declare a static unsigned char like so:
then copy your structure into the array like so:
now this where it is implementation specific next. I am using Borland C++ so my sending acts like so:
The reason I use ClientSendBuf[0] is because the size of my message is stored in ClientSendBuf[0] like so:
(Note: Replace struct with the name of your
struct)I also add a CRC check to the end of my message like so:
…
…
Basically all this simple CRC check is doing is summing all the bytes to determine that the correct number of bytes is sent. If the data should get mangled (which is common through buggy WiFi connections by the way), then the server should throw a CRC error.
This all assumes you have a POD struct. The
staticpart is not necessary, but how I did it in my particular application. I also glossed over some details. Post in the comments if you have questions. YMMV.