void send(){
PlayerPosPacket packet;
packet.x = x;
packet.y = y;
packet.player = id;
//char szBuffer[1024];
//SendData((char const *)&packet);
send(mySocket,(char const*)&packet,sizeof(packet),0);
//send(mySocket, buffer, strlen( buffer ), 0 );
ZeroMemory(&packet, sizeof(packet));
}
void recv(){
PlayerPosPacket recvPacket;
int r = recv( mySocket, (char *)&recvPacket, sizeof(recvPacket ), 0);
textprintf_ex(screen,font,0,0, makecol(0,255,0), -1, "x %d", recvPacket.x);
if(r > 0){
x2 = recvPacket.x;
y2 = recvPacket.y;
textprintf_ex(screen,font,0,0, makecol(0,255,0), -1, "x %d", recvPacket.x);
//ZeroMemory(&recvPacket, sizeof(recvPacket));
//allegro_message("here");
}else{}
}
The above code attempts to send the struct to another multi-client server I wrote. The server takes the data from one person and sends it to every other person except the one who send it in the first place. The problem is that I never receive the data I need to receive. I always receive either 0, or some other random number like 675390. Is there something wrong with my char* to struct. Please help me find the problem and fix it. It may be that I am missing some fundamental c++ skill that I somehow overlooked. (Although it is unlikely)
*edit*
What would be nice is an example of a client and a server sending a struct and then viewing the information.
forgot to mention, this is nonblocking.