TcpClient.LingerState 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定關聯通訊端延遲狀態的相關資訊。
public:
property System::Net::Sockets::LingerOption ^ LingerState { System::Net::Sockets::LingerOption ^ get(); void set(System::Net::Sockets::LingerOption ^ value); };
public System.Net.Sockets.LingerOption? LingerState { get; set; }
public System.Net.Sockets.LingerOption LingerState { get; set; }
member this.LingerState : System.Net.Sockets.LingerOption with get, set
Public Property LingerState As LingerOption
屬性值
LingerOption。 根據預設,會停用延遲。
範例
下列程式碼範例會設定並取得通訊端的閒置時間。
// sets the amount of time to linger after closing, using the LingerOption public property.
LingerOption^ lingerOption = gcnew LingerOption( true,10 );
tcpClient->LingerState = lingerOption;
// gets the amount of linger time set, using the LingerOption public property.
if ( tcpClient->LingerState->LingerTime == 10 )
Console::WriteLine( "The linger state setting was successfully set to {0}", tcpClient->LingerState->LingerTime );
// sets the amount of time to linger after closing, using the LingerOption public property.
LingerOption lingerOption = new LingerOption (true, 10);
tcpClient.LingerState = lingerOption;
// gets the amount of linger time set, using the LingerOption public property.
if (tcpClient.LingerState.LingerTime == 10)
Console.WriteLine ("The linger state setting was successfully set to " + tcpClient.LingerState.LingerTime.ToString ());
' Sets the amount of time to linger after closing, using the LingerOption public property.
Dim lingerOption As New LingerOption(True, 10)
tcpClient.LingerState = lingerOption
' Gets the amount of linger time set, using the LingerOption public property.
If tcpClient.LingerState.LingerTime = 10 Then
Console.WriteLine(("The linger state setting was successfully set to " + tcpClient.LingerState.LingerTime.ToString()))
End If
備註
屬性 LingerState
會變更方法的行為方式 Close 。 當設定 時,這個屬性會修改 Winsock 可重設連線的條件。 連線重設仍然可以根據 IP 通訊協定行為發生。
此屬性會控制 TCP 連線在呼叫 Close 之後,當資料繼續傳送之後,TCP 連線會保持開啟的時間長度。 當您呼叫 方法時 Write ,資料會放在傳出網路緩衝區中。 這個屬性可用來確保這個資料會在方法卸載連線之前 Close 傳送至遠端主機。
若要啟用移轉,請建立 LingerOption 包含所需值的實例,並將 屬性設定 LingerState
為這個實例。
下表描述 屬性可能值 Enabled 和 LingerTime 屬性中 LingerState
儲存之屬性之方法的行為 Close 。
LingerState.Enabled | LingerState.LingerTime | 行為 |
---|---|---|
false (停用) 預設值 |
逾時不適用, (預設) 。 | 嘗試傳送擱置的資料,直到預設 IP 通訊協定逾時到期為止。 |
true 已啟用 () |
非零逾時 | 嘗試傳送擱置的資料,直到指定的逾時到期為止,如果嘗試失敗,Winsock 就會重設連線。 |
true 已啟用 () |
零逾時。 | 捨棄任何擱置的資料,而 Winsock 會重設連線。 |
IP 堆疊會根據連線的來回時間計算要使用的預設 IP 通訊協定逾時期限。 在大部分情況下,堆疊所計算的逾時比應用程式所定義的逾時時間更相關。 這是未設定 屬性時 LingerState
通訊端的預設行為。
LingerTime當屬性中 LingerState
儲存的屬性設定大於預設 IP 通訊協定逾時,預設 IP 通訊協定逾時仍會套用並覆寫。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應