TcpClient.NoDelay 属性

定义

获取或设置一个值,该值在发送或接收缓冲区未满时禁用延迟。

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。 默认值为 false

示例

以下代码示例禁用延迟。 然后,它会检查 的值 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 {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

注解

当 为 falseNoDelayTcpClient在收集大量传出数据之前,不会通过网络发送数据包。 由于 TCP 段的开销很大,发送少量数据效率低下。 但是,确实存在需要发送极少量数据或期望从发送的每个数据包立即响应的情况。 你的决策应权衡网络效率与应用程序要求的相对重要性。

适用于