TcpClient.NoDelay 属性
定义
获取或设置一个值,该值在发送或接收缓冲区未满时禁用延迟。Gets or sets a value that disables a delay when send or receive buffers are not full.
public:
property bool NoDelay { bool get(); void set(bool value); };
public bool NoDelay { get; set; }
member this.NoDelay : bool with get, set
Public Property NoDelay As Boolean
属性值
true 如果禁用延迟,则为;否则为 false 。true if the delay is disabled; otherwise, false. 默认值为 false。The default value is false.
示例
下面的代码示例将禁用延迟。The following code example disables the delay. 然后,它将检查的值 NoDelay 以验证是否已成功设置该属性。It then checks the value of NoDelay to verify that the property was successfully set.
// Sends data immediately upon calling NetworkStream.Write.
tcpClient->NoDelay = true;
// Determines if the delay is enabled by using the NoDelay property.
if ( tcpClient->NoDelay == true )
Console::WriteLine( "The delay was set successfully to {0}", tcpClient->NoDelay );
// Sends data immediately upon calling NetworkStream.Write.
tcpClient.NoDelay = true;
// Determines if the delay is enabled by using the NoDelay property.
if (tcpClient.NoDelay == true)
Console.WriteLine ("The delay was set successfully to " + tcpClient.NoDelay.ToString ());
' Sends data immediately upon calling NetworkStream.Write.
tcpClient.NoDelay = True
' Determines if the delay is enabled by using the NoDelay property.
If tcpClient.NoDelay = True Then
Console.WriteLine(("The delay was set successfully to " + tcpClient.NoDelay.ToString()))
End If
注解
如果 NoDelay 为 false ,则在 TcpClient 收集到大量传出数据之前,不会通过网络发送数据包。When NoDelay is false, a TcpClient does not send a packet over the network until it has collected a significant amount of outgoing data. 由于 TCP 段中的开销很大,因此发送少量数据是低效的。Because of the amount of overhead in a TCP segment, sending small amounts of data is inefficient. 但是,在某些情况下,您需要发送非常少的数据,或者希望从每个发送的数据包立即响应。However, situations do exist where you need to send very small amounts of data or expect immediate responses from each packet you send. 决策应权衡网络效率与应用程序要求的相对重要性。Your decision should weigh the relative importance of network efficiency versus application requirements.