TcpClient.SendBufferSize 屬性

定義

取得或設定傳送緩衝區的大小。Gets or sets the size of the send buffer.

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

屬性值

傳送緩衝區的大小,以位元組為單位。The size of the send buffer, in bytes. 預設值為 8192 位元組。The default value is 8192 bytes.

範例

下列程式碼範例會設定並取得傳送緩衝區大小。The following code example sets and gets the send buffer size.

//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

備註

屬性會取得或設定每次呼叫NetworkStream.Write方法時預期要傳送的位元組數目。 SendBufferSizeThe SendBufferSize property gets or sets the number of bytes that you are expecting to send in each call to the NetworkStream.Write method. 這個屬性實際上會操作配置給傳送作業的網路緩衝區空間。This property actually manipulates the network buffer space allocated for send operation.

您的網路緩衝區應該至少與您的應用程式緩衝區一樣大,以確保所需的資料會在一項作業中儲存及傳送。Your network buffer should be at least as large as your application buffer to ensure that the desired data will be stored and sent in one operation. 請使用SendBufferSize屬性來設定此大小。Use the SendBufferSize property to set this size. 如果您的應用程式將會傳送大量資料,您應該Write將非常大型的應用程式緩衝區傳遞給方法。If your application will be sending bulk data, you should pass the Write method a very large application buffer.

如果網路緩衝區小於您提供Write方法的資料量,則會針對您對Write方法所做的每個呼叫執行數個網路傳送作業。If the network buffer is smaller than the amount of data you provide the Write method, several network send operations will be performed for every call you make to the Write method. 您可以藉由確保您的網路緩衝區至少與您的應用程式緩衝區一樣大,以達到更高的資料輸送量。You can achieve greater data throughput by ensuring that your network buffer is at least as large as your application buffer.

適用於

另請參閱