Export (0) Print
Expand All

TcpClient.ReceiveBufferSize Property

Gets or sets the size of the receive buffer.

Namespace: System.Net.Sockets
Assembly: System (in system.dll)

public int ReceiveBufferSize { get; set; }
/** @property */
public int get_ReceiveBufferSize ()

/** @property */
public void set_ReceiveBufferSize (int value)

public function get ReceiveBufferSize () : int

public function set ReceiveBufferSize (value : int)

Property Value

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

Exception typeCondition

SocketException

An error occurred when setting the buffer size.

-or-

In .NET Compact Framework applications, you cannot set this property. For a workaround, see the Platform Note in 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.

Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE Platform Note: This property is supported only on datagram oriented sockets, specified as SOCK_DGRAM sockets in Windows CE. The default receive buffer size is 32768 and cannot be set with this property.

The following code example sets and gets the receive buffer size.

// 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 ());


// Sets the receive buffer size using the ReceiveBufferSize public
// property.
tcpClient.set_ReceiveBufferSize(1024);

// Gets the receive buffer size using the ReceiveBufferSize public
// property.
if (tcpClient.get_ReceiveBufferSize() == 1024) {
    Console.WriteLine("The receive buffer was successfully set to "
        + ((Int32)tcpClient.get_ReceiveBufferSize()).ToString());
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft