Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ReceiveBufferSize Property

TcpClient.ReceiveBufferSize Property

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 the ReceiveBufferSize 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

See Also

TcpClient Class | TcpClient Members | System.Net.Sockets Namespace | SendBufferSize | Read

Show:
© 2015 Microsoft