Breyta

Deila með


TcpClient.ReceiveBufferSize Property

Definition

Gets or sets the size of the receive buffer.

public:
 property int ReceiveBufferSize { int get(); void set(int value); };
public int ReceiveBufferSize { get; set; }
member this.ReceiveBufferSize : int with get, set
Public Property ReceiveBufferSize As Integer

Property Value

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

Exceptions

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.

Examples

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 {0}", tcpClient->ReceiveBufferSize );
// 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.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

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.

Applies to

See also