I didn't think WSAGetLastError() changes the error. I just tried storing it and i get the same result...0.
EDIT: If i remove the condition, the socket still works and i can still receive packets.
EDIT: Now i just removed the "Disconnect()" so it only prints when it gets an error. It only prints once (rather than over and over again each time ::RecvPackets is called)
EDIT: Ok it prints every now and then. e.g
Code:
[07/16/08 23:18:27][SERVER] Listening on port 14804
[07/16/08 23:18:29][PLAYER:guest] New player has connected.
[07/16/08 23:18:29][PLAYER:guest] Sent..
[07/16/08 23:18:29][PLAYER:guest] Received: 37
[07/16/08 23:18:29][PLAYER:guest] Received: 39
[07/16/08 23:18:29][PLAYER:guest] Player left with socket error 0
[07/16/08 23:18:29][PLAYER:guest] Sent..
[07/16/08 23:18:29][PLAYER:guest] Received: 34
[07/16/08 23:18:29][PLAYER:guest] File Request: head1.png
[07/16/08 23:18:29][PLAYER:guest] Received: 34
[07/16/08 23:18:29][PLAYER:guest] File Request: body1.png
[07/16/08 23:18:29][PLAYER:guest] Received: 2
[07/16/08 23:18:29][PLAYER:guest] Received: 34
[07/16/08 23:18:29][PLAYER:guest] File Request: steps.wav
[07/16/08 23:18:29][PLAYER:guest] Received: 34
[07/16/08 23:18:29][PLAYER:guest] File Request: walk.gani
[07/16/08 23:18:29][PLAYER:guest] Received: 2
[07/16/08 23:18:30][PLAYER:guest] Received: 2
[07/16/08 23:18:30][PLAYER:guest] Received: 2
[07/16/08 23:18:30][PLAYER:guest] Received: 2
[07/16/08 23:18:30][PLAYER:guest] Received: 2
....
....
....
[07/16/08 23:19:25][PLAYER:guest] Player left with socket error 0
[07/16/08 23:19:25][PLAYER:guest] Received: 2
[07/16/08 23:19:25][PLAYER:guest] Received: 2
[07/16/08 23:19:25][PLAYER:guest] Received: 2
[07/16/08 23:19:25][PLAYER:guest] Received: 2
[07/16/08 23:19:25][PLAYER:guest] Received: 2
[07/16/08 23:19:27][PLAYER:guest] Received: 2
EDIT: Now i changed the receive code to this:
Code:
//Receive all the data
unsigned short received = 0;
size = socketId->Read(buffer, dataLen);
//while((size = socketId->Read(&buffer[received], dataLen - received)) > 0 && received < dataLen)
// received += size;
and it works but i get errors about the amount of bytes received not matching dataLen every now and then
EDIT!!!!:: Ok i fixed it
Code:
//Receive all the data
unsigned short received = 0;
while(received < dataLen)
{
if((size = socketId->Read(&buffer[received], dataLen - received)) > 0)
received += size;
else break;
}
It called recv one too many times (as it called recv before it checked if received < dataLen)