Receives data from a bound System.Net.Sockets.Socket into the list of receive buffers.
- buffers
- A list of ArraySegment`1s of type byte that contains the received data.
The number of bytes received.
This method reads data into the buffers parameter and returns the number of bytes successfully read. You can call from both connection-oriented and connectionless sockets.
This overload requires you to provide one or more receive buffers.
If you are using a connection-oriented protocol, you must either call Socket.Connect(System.Net.EndPoint) to establish a remote host connection, or Socket.Accept to accept an incoming connection prior to calling Socket.Receive(IList<ArraySegment<byte>>). The Socket.Receive(IList<ArraySegment<byte>>) method will only read data that arrives from the remote host connection established in the Socket.Connect(System.Net.EndPoint) or Socket.Accept method. If you are using a connectionless protocol, you can also use the Socket.ReceiveFrom(Byte[], int, int, SocketFlags, System.Net.EndPoint@) method. Socket.ReceiveFrom(Byte[], int, int, SocketFlags, System.Net.EndPoint@) will allow you to receive data arriving from any host.
If no data is available for reading, the Socket.Receive(IList<ArraySegment<byte>>) method will block until data is available, unless a time-out value was set by using Socket.ReceiveTimeout. If the time-out value was exceeded, the Socket.Receive(IList<ArraySegment<byte>>) call will throw a System.Net.Sockets.SocketException. If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the Socket.Receive(IList<ArraySegment<byte>>) method will complete immediately and throw a System.Net.Sockets.SocketException. You can use the Socket.Available property to determine if data is available for reading. When Socket.Available is non-zero, retry the receive operation.
If you are using a connection-oriented System.Net.Sockets.Socket, the Socket.Receive(IList<ArraySegment<byte>>) method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the System.Net.Sockets.Socket connection with the Socket.Shutdown(SocketShutdown) method, and all available data has been received, the Socket.Receive(IList<ArraySegment<byte>>) method will complete immediately and return zero bytes.
If you are using a connectionless System.Net.Sockets.Socket, Socket.Receive(IList<ArraySegment<System.Byte>>,System.Net.Sockets.SocketFlags) will read the first enqueued datagram from the destination address you specify in the Socket.Connect(System.Net.EndPoint) method. If the datagram you receive is larger than the size of the buffers parameter, buffers gets filled with the first part of the message, the excess data is lost and a System.Net.Sockets.SocketException is thrown.
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>].