Hello all,
Maybe someone can shed some light on this problem for me as ive ran out of ideas here. I have a client/server style game and dont have any probs on the server side but the client side is giving me a little trouble of late...
The clients are Windows and im using Asyncronous Sockets to handle my data in coming in. When I get an Async notification I use a switch to determine the notification type.. its the read im having problems with :
Code:
case FD_READ:
the_buf[0] = '\0';
bytes_in = recv(s, the_buf, sizeof(the_buf), 0);
if (bytes_in == 0)
{
MessageBox(DialogWindow, "Connection Closed","ERROR", MB_OK);
break;
}
if (bytes_in == WSAEWOULDBLOCK)
{
Sleep(750);
bytes_in= recv(s, the_buf, sizeof(the_buf), 0);
}
the_buf[bytes_in] = '\0';
process(DialogWindow, the_buf, bytes_in);
break;
Ok now the odd thing is that this has worked fine for quite a while but someone from America connected to the server the other night (Server is in UK) and would on rare occasions "miss" bits of data being sent to them.
For example if there were 3 of us connecting we may get the messages :
Blah enters the room.
Blah does something.
Blah leaves the room.
Note those are 3 different messages sent by the server, however on this one occasions the person in america didnt get the message "Blah does something", it just didnt display. My suspicion was that the data came through too fast and therefore couldnt be handled quick enough so I added in the check for a WSAEWOULDBLOCK, if it would block I would wait 750ms and then try again.
This still however didnt cure the problem, doing quite abit of testing with this person it was very intermitant and didnt occur everytime and was in fact quite rare but it could be a major problem for me if the client needs to know something and its not being processed.
Sorry for the ramble but I wanted to make the setup clear before I asked for suggestions. Is my checking for WSAEWOULDBLOCK not sufficient enough to determine if the socket is OK for reading ?
Im also confusing myself alot at the operating system level.. When the data leaves the server by a send() function is it then held in a queue by the operating system which tries to send the client or if the send function cannot get the packet out would it simply discard it ? In terms of incoming, does the data come into an internal windows buffer of some kind which then sends my program the read notification ?
Apologies for the rather long post but if someone could clear this up for me or point me in the right direction id appreciate it.
Thanks
Stan