Consider the following scenario (half-open connection):
The client has established stream connection with the server. If client crashes or a network error occurs (for example, intermediate router goes down), the server has no way of knowing this, unless it tries to use send(). In this case, send fails with the WSAECONNRESET error. If the server does not try to send data to a client, the connection is kept open on the server side for infinite amount of time.
Even if WSAAsyncSelect() with the FD_CLOSE parameter is used to determine loss of connection, event notification is not triggered. No events get posted because virtual circuit never go to a FIN WAIT or CLOSE WAIT state (crashed client never called shutdown or closesocket).
This situation can be avoided if keepalive probe packets are used. Note that keepalive probe packets are not a required part of the TCP specification. Keepalive packets are used to probe a connection that has been inactive for a long time. The peer initiates a disconnect when the probes do not get through. Keepalive packets for TCP connection can be turned on by using setsockopt() call with SO_KEEPALIVE option.
The following registry entries control keepalive probe packet parameters on computers running Windows NT or Windows 95 (note that not all of the entries can be found in the registry by default). Changing registry parameters affects all TCP/IP stream connections on the system.
KeepAliveInterval - This parameter determines the interval separating keep alive retransmissions until a response is received.
KeepAliveTime - This parameter controls how often TCP attempts to verify that an idle connection is still intact by sending a keep alive packet.
TcpMaxDataRetransmissions - This parameter controls the number of times TCP will retransmit an individual data segment (non-connect segment) before aborting the connection.
NOTE: The TcpMaxDataRetransmission parameter is NOT a valid setting under Windows 95. For additional information on valid TCP/IP registry parameters in Windows 95, please see the following article in the Microsoft Knowledge Base:
NOTE: To make the appropriate changes to the value above in the registry under Windows 95, go to the above location, click the Edit menu, point to New, and click String Value.
NOTE: To make the appropriate changes to the values above in the registry under Windows NT, go to the above location, click Add Value on the Edit menu. The Data Type should be REG_DWORD.
For information on how to configure above entries, please see the following article in the Microsoft Knowledge Base:
Article ID: 140325 - Last Review: Dec 4, 2003 - Revision: 1