I currently have a non-blocking server that is working great and sends 1 digit and 2 digit int values like a champ, but as soon as you go to 3 digits or more it seems to completely screw up. The first 3 digit value can be pulled from the buffer but the 2nd displays junk.
Here is my send function:
Player Send; - just a struct that holds 2 ints and a bool
char *sendbuffer;
sendbuffer = new char[200];
//Populate the buffer.
sendbuffer[0] = (char)Send.x;
sendbuffer[2] = (char)Send.y;
sendbuffer[4] = (char)Send.fight;
sendbuffer[6] = ''\0'';
// Hi-Ho Packet! AWAYYYYYYYYY!
send(socketinfo, &sendbuffer[0], strlen(sendbuffer),0);
if (socketinfo == SOCKET_ERROR)
{
send(socketinfo, &sendbuffer[0], strlen(sendbuffer),0);
}
ZeroMemory(sendbuffer,200);
delete [] sendbuffer;
and my Recv call:
char* recvbuffer;
recvbuffer = new char[200];
ZeroMemory(recvbuffer,200);
recv(Clients[a].Client,recvbuffer,200,0);
if (Clients[a].Client == SOCKET_ERROR)
{
recv(Clients[a].Client,recvbuffer,200,0);
}
if((int)recvbuffer[0] == -51 || (int)recvbuffer[0] == 0)
{
con.Clear();
Disconnect(a);
}
con << "Byte size : " << sizeof(recvbuffer) << "\n";
con << "X : " << (int)recvbuffer[0] << "\n";
con << "Y : " << (int)recvbuffer[2] << "\n";
con << "Fight : " << (int)recvbuffer[4] << "\n";
delete [] recvbuffer;
It works great for the first value if it''s greater than 2 digits but the others after the first are completely off from what they should be. Any ideas?
Also my disconnect call(you can see it in the recv source) doesn''t disconnect 2 clients if the clients try to disconnect at the same time, only one gets disconnected and the other is killed client side but the server''s disconnect is not called.
Any help would be appreciated