Assembly: System (in system.dll)
There may still be data available in the outgoing network buffer after you close the Socket. If you want to specify the amount of time that the Socket will attempt to transmit unsent data after closing, create a 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 Socket to remain connected before timing out. If you do not want the Socket to stay connected for any length of time after closing, create a LingerOption with the enable parameter set to true and the seconds parameter set to zero. In this case, the Socket will close immediately and any unsent data will be lost. Once created, pass the LingerOption to the Socket.SetSocketOption method. If you are sending and receiving data with a TcpClient, then pass the LingerOption to the TcpClient.LingerState method.
By default, lingering is enabled with a zero time-out. As a result, the Socket will attempt to send pending data until there is no data left in the outgoing network buffer.
The following example sets a previously created Socket to linger one second after calling the Close method.
LingerOption myOpts = new LingerOption(true,1); mySocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, myOpts);
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.