This documentation is archived and is not being maintained.

Socket.Available Property

Gets the amount of data that has been received from the network and is available to be read.

[Visual Basic]
Public ReadOnly Property Available As Integer
public int Available {get;}
public: __property int get_Available();
public function get Available() : int;

Property Value

The number of bytes of data received from the network and available to be read.


Exception Type Condition
SocketException An error occurred when attempting to access the socket. See the Remarks section for more information.
ObjectDisposedException The Socket has been closed.


If you are using a non-blocking Socket, Available is a good way to determine whether data is queued for reading, before calling Receive. With Stream Socket types, the available data is the total amount of data queued in the network buffer for reading. If you are using a message-oriented socket type such as Dgram, the available data is the first message in that buffer. If no data is queued in the network buffer, Available returns 0.

If the remote host shuts down or closes the connection, Available throws a SocketException. If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code. Once you have obtained this code, you can refer to the Windows Socket Version 2 API error code documentation in MSDN for a detailed description of the error.


[C#, C++] The following code example compares the results of calling IOControl with FIONREAD and the Available property.

// FIONREAD is also available as the "Available" property.
       public const int FIONREAD   = 0x4004667F;
       static void DisplayPendingByteCount(Socket s)
    byte[] outValue = BitConverter.GetBytes(0);

    // Check how many bytes have been received.
    s.IOControl(FIONREAD, null, outValue);
    uint bytesAvailable = BitConverter.ToUInt32(outValue, 0);
    Console.WriteLine("server has {0} bytes pending. Available property says {1}.",
        bytesAvailable, s.Available);

// FIONREAD is also available as the "Available" property.
const int FIONREAD   = 0x4004667F;

void DisplayPendingByteCount(Socket* s)
    Byte outValue[] = BitConverter::GetBytes(0);

    // Check how many bytes have been received.
    s->IOControl(FIONREAD, 0, outValue);

    UInt32 bytesAvailable = BitConverter::ToUInt32(outValue, 0);
    Console::WriteLine(S"server has {0} bytes pending. Available property says {1}.", __box(bytesAvailable), __box(s->Available));


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


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, Common Language Infrastructure (CLI) Standard

See Also

Socket Class | Socket Members | System.Net.Sockets Namespace | Receive | Stream | Dgram