NetworkStream.ReadByte Method

Definition

Reads a byte from the NetworkStream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.

C#
public override int ReadByte();

Returns

The unsigned byte cast to an Int32, or -1 if at the end of the stream because the peer socket performed a graceful shutdown.

Exceptions

The NetworkStream does not support reading.

An error occurred when accessing the socket.

-or-

There is a failure reading from the network.

Remarks

Poznámka

Check to see if the NetworkStream is readable by calling the CanRead property. If you attempt to read from a NetworkStream that is not readable, you will get an InvalidOperationException.

Poznámka

If you receive an IOException, check the InnerException property to determine if it was caused by a SocketException. If so, use the ErrorCode property 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

Produkt Verzie
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1