UdpClient.Available Property

Definition

Gets the amount of data received from the network that is available to read.

public int Available { get; }

Property Value

The number of bytes of data received from the network.

Exceptions

An error occurred while attempting to access the socket.

The Socket has been closed.

Examples

The following code example shows the use of the Available property.

public static void GetAvailable(UdpClient u)
{
    // Get the number of bytes available for reading.
    Console.WriteLine("Available value is {0}",
        u.Available);
}

Remarks

The Available property is used to determine the amount of data queued in the network buffer for reading. If data is available, call Read to get the data. If no data is available, the Available property returns 0.

If the remote host shuts down or closes the connection, the Available property throws a SocketException.

Note

If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code and refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1