LingerOption LingerOption LingerOption LingerOption Class


指定在调用 SocketClose() 方法之后,如果仍有数据要发送,Close() 是否保持连接以及保持多长时间。Specifies whether a Socket will remain connected after a call to the Close() or Close() methods and the length of time it will remain connected, if data remains to be sent.

public ref class LingerOption
public class LingerOption
type LingerOption = class
Public Class LingerOption


下面的示例设置之前创建Socket逗留一秒后调用Close方法。The following example sets a previously created Socket to linger one second after calling the Close method.

LingerOption^ myOpts = gcnew LingerOption( true,1 );
mySocket->SetSocketOption( SocketOptionLevel::Socket, SocketOptionName::Linger, myOpts );
LingerOption myOpts = new LingerOption(true,1);

mySocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, myOpts);

Dim myOpts As New LingerOption(True, 1)
mySocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, _


可能仍有数据可用的传出的网络缓冲区中后应用程序调用SocketTcpClient方法。There may still be data available in the outgoing network buffer after an application calls the Socket or TcpClient method. 如果你想要指定的时间Socket将尝试关闭后传输未发送的数据,创建LingerOptionenable参数设置为true,和seconds参数设置为所需的时间量.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. seconds参数用于指示多长时间想Socket将保持连接才会超时。如果不希望Socket保持为任意长度的时间后关闭连接,创建LingerOption实例与enable参数设置为trueseconds参数设置为零。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 instance with the enable parameter set to true and the seconds parameter set to zero. 在这种情况下,Socket将立即关闭,所有未发送的数据都将丢失。In this case, the Socket will close immediately and any unsent data will be lost. 创建后,将传递LingerOptionSocket.SetSocketOption方法。Once created, pass the LingerOption to the Socket.SetSocketOption method. 如果发送和接收的数据与TcpClient,然后设置LingerOption实例中TcpClient.LingerState属性。If you are sending and receiving data with a TcpClient, then set the LingerOption instance in the TcpClient.LingerState property.

IP 堆栈计算默认 IP 协议的超时期限为使用基于连接的往返行程时间。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. 这是默认行为SocketLingerState属性未设置以及TcpClientLingerState未设置属性。This is the default behavior for a Socket when the LingerState property is not set and for a TcpClient when the LingerState property is not set.


LingerOption(Boolean, Int32) LingerOption(Boolean, Int32) LingerOption(Boolean, Int32) LingerOption(Boolean, Int32)

初始化 LingerOption 类的新实例。Initializes a new instance of the LingerOption class.


Enabled Enabled Enabled Enabled

获取或设置一个值,指示 Socket 关闭后是否逗留。Gets or sets a value that indicates whether to linger after the Socket is closed.

LingerTime LingerTime LingerTime LingerTime

获取或设置在调用 Close() 方法后仍有数据要发送的情况下将保持连接的时间量。Gets or sets the amount of time to remain connected after calling the Close() method if data remains to be sent.


Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)