Original Post
I am using the TCP/IP protocol with C++: I have a packet on the client that looks like this-
#pragma pack(1)
struct Packet1 {
float x;
float y;
float z;
float heading;
};
And currently I have it sending like this:
Packet p1;
p1.x=x;
p1.y=y;
p1.z=z;
p1.heading=heading;
send(socket1,"1",1,0); //Opcode '1' (XYZ Updates)
send(socket1,(char *)&p1,sizeof(Packet1),0); //Actual packet
----------- The server has the same packet definition, and receives it in the same way. The server would call recv() on a 1-byte size, and check to see what the opcode sent was like:
size = recv(tempScanNode->socket,opcode,1,0);
if (size>0) {
if (opcode == "1") {
recv(tempScanNode->socket,(char *)coordPacket,sizeof(Packet1),0);
DoCoordUpdate(&coordPacket)
}
}
Something similar to that. What I am wondering is that a good way to handle packets--and also I wanted to handle the packets this way but can't seem to find a way: Send just 1 packet (instead of 1 opcode packet and 1 payload packet) with a packet opcode in the struct, and send it off. But there is no way to know which packet struct to recv() it on because there will be many packets of many sizes. Any help appreciated. [Edited by - Leaedas on November 21, 2009 3:19:08 PM]