In a client/server system I am writing I simulated a network breakdown in the following way:

Let server and client run on each their machine on local LAN with a switch between them.
The client will send my own "keep alive" data to the server every 30 seconds to see if server is still up. Now I turn off the switch and see what happens.
After 30 seconds the client would detect the socket is invalid so it will try to reconnect to the server. However I expected that the server would detect that the client socket is invalid too and by calling one of the network functions it would say the client disconnected ungracefully because of a socket error. This didn't happen though. Instead it says that the client is still alive.

Reading in:
http://tangentsoft.net/wskfaq/newbie.html#abnormalclose

tells me that there is a default timeout on 2 hours so I wanted to change this timeout.

The following code I wrote to try to change this timeout:

int nTimeout = 5*60*1000;

if (setsockopt(lpPI->remoteSocket, SOL_SOCKET, SO_RCVTIMEO, (char *) &nTimeout, sizeof(nTimeout)) == SOCKET_ERROR)
return false;
if (setsockopt(lpPI->remoteSocket, SOL_SOCKET, SO_SNDTIMEO, (char *) &nTimeout, sizeof(nTimeout)) == SOCKET_ERROR)
return false;

which should set the timeout down to 5 min. Still it doens't work as it should on the server. Both calls return 0 as they should and I tried both lines on both client and server.

Additionally I also enabled SO_KEEPALIVE on the client to ensure that the connection doesn't timeout when both client and server are still running.

The system I wrote is initialized as winsock 1.1.

Maybe someone got a clue?

Thanks in advance.

// CyberHeg
Posted on 2003-04-07 02:53:58 by CyberHeg
umm unsure about winsock1, but in winsock2 is a proc called WSAWaitForMultipleEvents which can be used to set up a "networking event object", which can monitor all the FD messages at once, and can do so for multiple simultaneous sockets. Disregarding that, its got a built-in timer via one of its params you get to specify an idle timeout. Hope that helps.
I used it when I needed to code a multisocketed clientside tool, which the api is not really geared towards. That timeout came in handy.
Posted on 2003-04-08 10:36:24 by Homer