First of all, hi to everybody. Nice place you got here.
If you have some UDP experience you probably already understood my problem:
I have a server and a number of clients connected to it(logically connected since this is using UDP). Server has only one socket/port and sends data out of this port to all of the clients. If for some reason one of the clients disconnect un-gracefully(e.g. Ctrl-C, End Process, etc.) the recvfrom() command returns a WSAECONNRESET(yes I read about it, the reason is ICMP). This isn't a problem on its own but the real problem is that the server fails to receive further packets from clients.
From what I google'd so far it seems at some point even Serious Sam suffered from this, there is an article on a pixelate mag that specifically points out this error code, a Win2K fix, and a bunch of confused people posting at various forums.
I looked at the Q3 code and no special care is taken to handle this situation, although I use the exact same socket creation and configuration code.
My current fix is when I get a WSAECONNRESET, I label that client as dead and remove it. This fixes the problem. But I feel a little uneasy about that solution since Q3 does not use such a failsafe for this.
Can anyone offer any help on this issue?
This must have happened to you too (WSAECONNRESET)
Started by leblebi, Sep 14 2005 01:47 PM
2 replies to this topic
#1
Posted 14 September 2005 - 01:47 PM
#2
Posted 14 September 2005 - 01:56 PM
I did some network code for a game a few years ago, of course we also used UDP but I don't think we did anything with the WSAECONNRESET error... I think I have the source somewhere, I'll take a look at it.
But what I don't understand is why the server shouldn't receive any more messages. But you could try to reinitialize the socket and continue sending/receiving, although that might fuck up the current receive buffer... (but then again, that buffer isn't going to be of much use if you're not able to read it anyway)
But what I don't understand is why the server shouldn't receive any more messages. But you could try to reinitialize the socket and continue sending/receiving, although that might fuck up the current receive buffer... (but then again, that buffer isn't going to be of much use if you're not able to read it anyway)
#3
Posted 15 September 2005 - 12:58 PM
I found the reason and the fix to the problem.
If you have a non-blocking recvfrom() loop like this to read from your socket, you are doing the wrong thing:
Because WSAECONNRESET obviously causes a SOCKET_ERROR but actually there is no error and you should keep reading the socket when WSAECONNRESET occurs. So it should read something like this;
It turns out that Q3 is actually handling this issue like this. It also includes the WSAWOULDBLOCK as an OK to read error.
If you have a non-blocking recvfrom() loop like this to read from your socket, you are doing the wrong thing:
do
{
ret = recvfrom(...);
if ( ret != SOCKET_ERROR )
dispatch_data ();
}while ( ret != SOCKET_ERROR )
Because WSAECONNRESET obviously causes a SOCKET_ERROR but actually there is no error and you should keep reading the socket when WSAECONNRESET occurs. So it should read something like this;
do
{
ret = recvfrom(...);
if ( ret == SOCKET_ERROR )
err = WSAGetLastError ( );
else
dispatch_data ();
}while ( ret != SOCKET_ERROR || ( ret == SOCKET_ERROR && err == WSAECONNRESET ) )
It turns out that Q3 is actually handling this issue like this. It also includes the WSAWOULDBLOCK as an OK to read error.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











