Reads data from the System.Net.Sockets.NetworkStream.
- buffer
- An array of type byte that is the location in memory to store data read from the System.Net.Sockets.NetworkStream.
- offset
- The location in buffer to begin storing the data to.
- size
- The number of bytes to read from the System.Net.Sockets.NetworkStream.
The number of bytes read from the System.Net.Sockets.NetworkStream.
Type Reason ArgumentNullException buffer is null. ArgumentOutOfRangeException offset < 0.
-or-
offset > buffer.Length.
-or-
size < 0.
-or-
size > buffer.Length - offset.
System.IO.IOException Note: This method catches all exceptions thrown by the Socket.Receive(Byte[], int, SocketFlags) method.ObjectDisposedException The current instance has been disposed.
This method reads data into the buffer parameter and returns the number of bytes successfully read. If no data is available for reading, the NetworkStream.Read(Byte[], int, int) method returns 0. The NetworkStream.Read(Byte[], int, int) operation reads as much data as is available, up to the number of bytes specified by the size parameter. If the remote host shuts down the connection, and all available data has been received, the NetworkStream.Read(Byte[], int, int) method completes immediately and return zero bytes.
Check to see if the System.Net.Sockets.NetworkStream is readable by calling the NetworkStream.CanRead property. If you attempt to read from a System.Net.Sockets.NetworkStream that is not readable, you will get an System.IO.IOException.
If you receive an System.IO.IOException, check the Exception.InnerException property to determine if it was caused by a System.Net.Sockets.SocketException. If so, use the SocketException.ErrorCode property to obtain the specific error code, and refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error.