Originally Posted by
Elysia
Your software must agree on a common format, not just raw data. This is essential, especially due to padding. It would be the first step, I think. Make functions that can basically transform a struct into char array with data (which would individually convert each member of the struct), and vice versa.
I've got the internal structs all straightened out now (there were only 2, so it wasn't much of a problem). Now the stuff that has to travel by datagram...
UDP datagrams are naturally byte arrays so converting from internal struct to one that overlays a blank datagram is pretty easy. This part has, in fact, been working perfectly from the beginning... so long as I give it good data to work with there's never been a miscommunication.
For example:
Code:
#pragma pack(1)
// datagram structure
typedef struct tDATAGRAM
{ DWORD PassCode; // Passcode
TCHAR Guard1; // always 0
BYTE Command; // command byte
TCHAR Guard2; // always 0
BYTE Data[MAX_DGRAMDATA]; } // data field
DATAGRAM, *pDATAGRAM;
#pragma pack()
This definition, as well as the definitions of structs to be transmitted, is globalized on both client and server. (same header file used on both)
To send a datagram I overlay a struct or string on the Data field and, so far, no errors of any kind. Most of the structs being used are specific to this function... for example a packet to send the current system time is in a DG_TIME struct that is loaded from the windows time functions. I don't just send the windows time struct. The only case where I was loading a struct into memory and transmitting it directly was the one that tripped me up... the rest of it all seems to work well enough.
But I do confess that my confidence in this is now rattled...
So.. how worried should I be???