TcpClient.SendBufferSize 屬性

定義

取得或設定傳送緩衝區的大小。

public:
 property int SendBufferSize { int get(); void set(int value); };
public int SendBufferSize { get; set; }
member this.SendBufferSize : int with get, set
Public Property SendBufferSize As Integer

屬性值

傳送緩衝區的大小,以位元組為單位。 預設值為 8192 位元組。

範例

下列程式碼範例會設定並取得傳送緩衝區大小。

//sets the send buffer size using the SendBufferSize public property.
tcpClient->SendBufferSize = 1024;

// gets the send buffer size using the SendBufferSize public property.
if ( tcpClient->SendBufferSize == 1024 )
      Console::WriteLine( "The send buffer was successfully set to {0}", tcpClient->SendBufferSize );
// Sets the send buffer size using the SendBufferSize public property.
tcpClient.SendBufferSize = 1024;

// Gets the send buffer size using the SendBufferSize public property.
if (tcpClient.SendBufferSize == 1024)
    Console.WriteLine ("The send buffer was successfully set to " + tcpClient.SendBufferSize.ToString ());
'Sets the send buffer size using the SendBufferSize public property.
tcpClient.SendBufferSize = 1024

' Gets the send buffer size using the SendBufferSize public property.
If tcpClient.SendBufferSize = 1024 Then
   Console.WriteLine(("The send buffer was successfully set to " + tcpClient.SendBufferSize.ToString()))
End If

備註

屬性 SendBufferSize 會取得或設定您預期在每個方法呼叫 NetworkStream.Write 中傳送的位元組數目。 此屬性實際上會操作配置給傳送作業的網路緩衝區空間。

您的網路緩衝區應該至少與應用程式緩衝區一樣大,以確保所需的資料會儲存並傳送到一個作業中。 使用 SendBufferSize 屬性來設定此大小。 如果您的應用程式將傳送大量資料,您應該傳遞 Write 方法非常大型的應用程式緩衝區。

如果網路緩衝區小於您提供 Write 方法的資料量,則會針對您對 方法進行 Write 的每個呼叫執行數個網路傳送作業。 您可以確保網路緩衝區至少與應用程式緩衝區一樣大,以達到更高的資料輸送量。

適用於

另請參閱