You are currently offline, waiting for your internet to reconnect

How to Determine Loss of Client/Server Connection

This article was previously published under Q140325
This article has been archived. It is offered "as is" and will no longer be updated.
This article explains how to use keepalive probes to determine loss ofstream connection.
In the context of this article, the "client" is the peer computerrequesting a connection, and the "server" is the peer computer accepting aconnection. This notation does not reflect Client/Server relationships asan architectural principal.

Consider the following scenario (half-open connection):

The client has established stream connection with the server. If clientcrashes or a network error occurs (for example, intermediate router goesdown), the server has no way of knowing this, unless it tries to usesend(). In this case, send fails with the WSAECONNRESET error. If theserver does not try to send data to a client, the connection is kept openon the server side for infinite amount of time.

Even if WSAAsyncSelect() with the FD_CLOSE parameter is used to determineloss of connection, event notification is not triggered. No events getposted 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. Notethat keepalive probe packets are not a required part of the TCPspecification. Keepalive packets are used to probe a connection that hasbeen inactive for a long time. The peer initiates a disconnect when theprobes do not get through. Keepalive packets for TCP connection can beturned on by using setsockopt() call with SO_KEEPALIVE option.

The following registry entries control keepalive probe packet parameters oncomputers running Windows NT or Windows 95 (note that not all of theentries can be found in the registry by default). Changing registryparameters affects all TCP/IP stream connections on the system.

KeepAliveInterval - This parameter determines the interval separating keepalive retransmissions until a response is received.

KeepAliveTime - This parameter controls how often TCP attempts to verifythat an idle connection is still intact by sending a keep alive packet.

TcpMaxDataRetransmissions - This parameter controls the number of times TCPwill retransmit an individual data segment (non-connect segment) beforeaborting the connection.

NOTE: The TcpMaxDataRetransmission parameter is NOT a valid setting underWindows 95. For additional information on valid TCP/IP registry parametersin Windows 95, please see the following article in the Microsoft KnowledgeBase:
158474 Windows 95 TCP/IP Registry Entries
The above entries are found in following registry locations:

Windows 95

   \HKEY_LOCAL_MACHINE    \System     \CurrentControlSet      \Services       \VxD        \MSTCP				
NOTE: To make the appropriate changes to the value above in the registryunder Windows 95, go to the above location, click the Edit menu, point toNew, and click String Value.

Windows NT

   \HKEY_LOCAL_MACHINE    \System     \CurrentControlSet      \Services       \TCPIP        \Parameters				
NOTE: To make the appropriate changes to the values above in the registryunder Windows NT, go to the above location, click Add Value on the Editmenu. The Data Type should be REG_DWORD.

For information on how to configure above entries, please see the followingarticle in the Microsoft Knowledge Base:
120642 TCP/IP and NBT Configuration Parameters for Windows 2000 or Windows NT
IMPORTANT: After you alter the registry, you must restart your computer.

Article ID: 140325 - Last Review: 12/04/2015 12:28:41 - Revision: 3.0

Microsoft Windows NT Workstation 3.5, Microsoft Windows NT Workstation 3.51, Microsoft Windows NT Workstation 4.0 Developer Edition, Microsoft Windows NT Server 3.5, Microsoft Windows NT Server 3.51, Microsoft Windows NT Server 4.0 Standard Edition, Microsoft Windows 95

  • kbnosurvey kbarchive kbinfo kbnetwork KB140325