System.Net.Sockets.Socket.Available Property

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

Syntax

public int Available { get; }

Value

A int containing the number of bytes of data that are available to be read.

Exceptions

TypeReason
System.Net.Sockets.SocketException
Note: For additional information on causes of the SocketException, see the System.Net.Sockets.SocketException class.
ObjectDisposedExceptionThe current instance has been disposed.

Remarks

If you are using a non-blocking System.Net.Sockets.Socket, Socket.Available is a good way to determine whether data is queued for reading, before calling Socket.Receive(Byte[], int, SocketFlags). The available data is the total amount of data queued in the network buffer for reading. If no data is queued in the network buffer, Socket.Available returns 0.

If the remote host shuts down or closes the connection, Socket.Available can throw a System.Net.Sockets.SocketException. If you receive a System.Net.Sockets.SocketException, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

Note:

This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0