TcpClient.NoDelay 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當傳送或接收緩衝區未滿時,會設定一個值,使延遲失效。
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)
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,a TcpClient 在收集大量外出資料之前,不會透過網路傳送封包。 由於 TCP 區段的開銷較大,傳送少量資料效率較低。 然而,確實存在需要傳送非常少量資料,或期望每個封包立即回應的情況。 您的決策應權衡網路效率與應用需求之間的相對重要性。