Socket timeout not expired when the client socket shutdowns

Hi,
I have a socket communication in .NET 2.0, with a server socket that accepts many client sockets, creating a thread foreach client.
I want to close the communications that don't send data within n minutes from the last communication; so I set timeout option in the client socket with this code:

Socket socket = sListener.Accept();
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, n * 60 * 1000);


This timeout expires as expected when the client doesn't close his socket. But if the client closes his socket before the timeout expires, the timeout doesn' t expire and so the server can't close the communication.
Are there other ways to do this
I've tried with setting a KeepAlive, in hopes to get an exception when the server tried to keep alive the dead client, but it doesn't work.
I've used this snippet:
http://blogs.msdn.com/lcleeton/default.aspx

Thanks for any help.
Stefano


Answer this question

Socket timeout not expired when the client socket shutdowns

  • blah569

    I found the problem.
    There isn't any timeout expirations when the client shutdowns the connection; I had to recognize it managing the "zero" result from the "Socket.Receive" method.
    Thanks
    Stefano

  • Socket timeout not expired when the client socket shutdowns