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 方法时都会执行多个网络发送操作。 通过确保网络缓冲区至少与应用程序缓冲区一样大,可以实现更高的数据吞吐量。

适用于

另请参阅