TcpClient.ReceiveBufferSize Property

【问题背景】

在loadrunner中利用lrs_receive函数收取一个1712366 bytes大小的数据包时,回放日志中出现如下信息。当时不明白为什么那么多的的8192。

 

【相关知识】

 

Gets or sets the size of the receive buffer.

[Visual Basic]
Public Property ReceiveBufferSize As Integer
[C#]
public int ReceiveBufferSize {get; set;}
[C++]
public: __property int get_ReceiveBufferSize();
public: __property void set_ReceiveBufferSize(int);
[JScript]
public function get ReceiveBufferSize() : int;
public function set ReceiveBufferSize(int);
Property Value

The size of the receive buffer, in bytes. The default value is 8192 bytes.

Remarks

The ReceiveBufferSize property gets or sets the number of bytes that you are expecting to store in the receive buffer for each read operation. This property actually manipulates the network buffer space allocated for receiving incoming data.

Your network buffer should be at least as large as your application buffer to ensure that the desired data will be available when you call the NetworkStream.Read method. Use theReceiveBufferSize property to set this size. If your application will be receiving bulk data, you should pass the Read method a very large application buffer.

If the network buffer is smaller than the amount of data you request in the Read method, you will not be able to retrieve the desired amount of data in one read operation. This incurs the overhead of additional calls to the Read method.

Example

[Visual Basic, C#, C++] The following example sets and gets the receive buffer size.

[Visual Basic] 
' 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

[C#] 
// 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 ());


[C++] 
// 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(S"The receive buffer was successfully set to {0}", __box(tcpClient->ReceiveBufferSize));

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值