Small question about packet format...

Started by
0 comments, last by TheTempest 21 years, 8 months ago
Hi all, background info: i''m using win32, async sockets... i can connect, recv, send, accept, close sockets // psuedo code struct packet1 { char userName[30]; char userPass[30]; } //size 60 bytes struct packet2 { int playerX; int playerY; } // size 8 bytes i know to send the struct you would do this: send(socket,(char*)&packet1,sizeof(packet1),0); but, if the server is blind, how can it distenguish between the two packets? I.E. i have read a tutorial on how to build a HTTP server/client, and the server and client can distuenquish between the two because they read the char arry to find sentienals. but u can''t do that w/ints... Any help would be greately appriciated, and i''m sure its something simple i can''t think of or find THX
"There are no such things as stupid questions...Just stupid people :)"-Me
Advertisement
You need to send an identification with every packet you send, so the server knows exactly what it is trying to receive. A good idea is to have the size, and type of a packet at the start of every packet. First the receiver reads the size, and then reads that many bytes from the network. Then it can look at the type id of the packet it has just read in, and then blind cast it to the proper struct.

This topic is closed to new replies.

Advertisement