What you can do, is make the first byte (or maybe 2 bytes if you plan to have a ton of messages) be a special code that says what "type" the packet is. I'm gonna pull some random examples out now, you can of course use whatever numbers you want.
unsigned char message[20];#define WALKPACKET 0x01#define TALKPACKET 0x02#define UPDATEPOSITION 0x03// Now if you want to send a talk packet, for example, do something likemessage[0]=TALKPACKET;strcpy(&message[1],"I am saying this stuff");// then put the winsock send commandsend(message,some other stuff, you know the drill);now, on the server end, it gets this packet, and you can do something like thisrecv(message, some other crap, etc);switch(message[0]){ case WALKPACKET: // They sent us a packet whose first byte was 0x01, do something approproate break; case TALKPACKET: cout << "They said " << &message[1] << endl; break; case UPDATEPOSITION: // do something break; default: cout << "Error, unknown packet!" << endl;}
Do you get the idea? Rather than waste a ton of space sending "password=adjojd" you just send one byte that is "code" for "password=". It is still excess bandwidth, but honestly, who gives a crap about one byte?
Did that answer your question?
(Edit: the formatting was totally wierd, I tried to fix it)
Anthracks
Edited by - Anthracks on March 7, 2001 2:23:49 PM