System.Net.Sockets.LingerOption Class

Specifies whether a System.Net.Sockets.Socket will remain connected after a call to the Socket.Close or TcpClient.Close methods and the length of time it will remain connected, if data remains to be sent.

See Also: LingerOption Members

Syntax

public class LingerOption

Remarks

There may still be data available in the outgoing network buffer after an application calls the System.Net.Sockets.Socket or System.Net.Sockets.TcpClient method. If you want to specify the amount of time that the System.Net.Sockets.Socket will attempt to transmit unsent data after closing, create a System.Net.Sockets.LingerOption with the enable parameter set to true, and the seconds parameter set to the desired amount of time. The seconds parameter is used to indicate how long you would like the System.Net.Sockets.Socket to remain connected before timing out. If you do not want the System.Net.Sockets.Socket to stay connected for any length of time after closing, create a System.Net.Sockets.LingerOption instance with the enable parameter set to true and the seconds parameter set to zero. In this case, the System.Net.Sockets.Socket will close immediately and any unsent data will be lost. Once created, pass the System.Net.Sockets.LingerOption to the Socket.SetSocketOption(SocketOptionLevel, SocketOptionName, int) method. If you are sending and receiving data with a System.Net.Sockets.TcpClient, then set the System.Net.Sockets.LingerOption instance in the TcpClient.LingerState property.

The IP stack computes the default IP protocol time-out period to use based on the round trip time of the connection. In most cases, the time-out computed by the stack is more relevant than one defined by an application. This is the default behavior for a System.Net.Sockets.Socket when the Socket.LingerState property is not set and for a System.Net.Sockets.TcpClient when the TcpClient.LingerState property is not set.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 1.0.x.x, 1.0.5000.0, 2.0.0.0, 4.0.0.0