ServicePoint::ReceiveBufferSize Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the size of the receiving buffer for the socket used by this ServicePoint.

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

public:
property int ReceiveBufferSize {
	int get();
	void set(int value);
}

Property Value

Type: System::Int32

A Int32 that contains the size, in bytes, of the receive buffer. The default is 8192.

Exception Condition
ArgumentOutOfRangeException

The value specified for a set operation is greater than MaxValue.

For additional information, see ReceiveBufferSize.

The following code example sets the value of this property.

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::IO;
using namespace System::Threading;

namespace SystemNetExamples
{
    public ref class ServicePointExample
    {
    public:

        // Pass in the name of the Web page to retrieve.    
        static void PrintResponse(String^ page)
        {

            // Create the request.
            HttpWebRequest^ request;
            Uri^ uri;



            try
            {
                uri = gcnew Uri(page);
            }
            catch (UriFormatException^ ex) 
            {
                Console::WriteLine(ex->Message);
            }

            request = (HttpWebRequest^) WebRequest::Create(uri); 

            // Get the service point that handles the request's 
            // socket connection.
            ServicePoint^ point = request->ServicePoint;

            // Set the receive buffer size on the underlying socket.
            point->ReceiveBufferSize = 2048;

            // Set the connection lease timeout to infinite.
            point->ConnectionLeaseTimeout = Timeout::Infinite;

            // Send the request.
            HttpWebResponse^ response = 
                (HttpWebResponse^) request->GetResponse();
            Stream^ responseStream = response->GetResponseStream();
            StreamReader^ streamReader = 
                gcnew StreamReader(responseStream);
            try
            {
                // Display the response.
                Console::WriteLine(streamReader->ReadToEnd());
                responseStream->Close();
                response->Close();
            }
            finally
            {
                streamReader->Close();
            }
        }
    };
}

.NET Framework
Available since 2.0
Return to top
Show: