TcpClient.ReceiveBufferSize 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定接收緩衝區的大小。
public:
property int ReceiveBufferSize { int get(); void set(int value); };
public int ReceiveBufferSize { get; set; }
member this.ReceiveBufferSize : int with get, set
Public Property ReceiveBufferSize As Integer
屬性值
接收緩衝區的大小,以位元組為單位。 預設值為 8192 位元組。
例外狀況
設定緩衝區大小時發生錯誤。
-或-
在 .NET Compact Framework 應用程式中,您無法設定這個屬性。 如需解決方法,請參閱<註解>中的<平台注意事項>。
範例
下列程式代碼範例會設定並取得接收緩衝區大小。
// sets the receive buffer size using the ReceiveBufferSize public property.
tcpClient->ReceiveBufferSize = 1024;
// gets the receive buffer size using the ReceiveBufferSize public property.
if ( tcpClient->ReceiveBufferSize == 1024 )
Console::WriteLine( "The receive buffer was successfully set to {0}", tcpClient->ReceiveBufferSize );
// Sets the receive buffer size using the ReceiveBufferSize public property.
tcpClient.ReceiveBufferSize = 1024;
// Gets the receive buffer size using the ReceiveBufferSize public property.
if (tcpClient.ReceiveBufferSize == 1024)
Console.WriteLine ("The receive buffer was successfully set to " + tcpClient.ReceiveBufferSize.ToString ());
' Sets the receive buffer size using the ReceiveBufferSize public property.
tcpClient.ReceiveBufferSize = 1024
' Gets the receive buffer size using the ReceiveBufferSize public property.
If tcpClient.ReceiveBufferSize = 1024 Then
Console.WriteLine(("The receive buffer was successfully set to " + tcpClient.ReceiveBufferSize.ToString()))
End If
備註
屬性 ReceiveBufferSize
會取得或設定您想要在每個讀取作業的接收緩衝區中儲存的位元元組數目。 這個屬性實際上會操作配置來接收傳入數據的網路緩衝區空間。
您的網路緩衝區應該至少與應用程式緩衝區一樣大,以確保當您呼叫 NetworkStream.Read 方法時,將會有所需的數據可用。
ReceiveBufferSize使用屬性來設定這個大小。 如果您的應用程式將接收大量數據,您應該傳遞 Read
非常大型的應用程式緩衝區方法。
如果網路緩衝區小於您在 方法中 Read
要求的數據量,您將無法在一個讀取作業中擷取所需的數據量。 這會產生方法額外呼叫 Read
的額外負荷。