- result
- A IAsyncResult object that holds the state information for the asynchronous operation.
The number of bytes received.
Type Reason ArgumentNullException asyncResult is null. ArgumentException asyncResult was not returned by the current instance from a call to the Socket.BeginReceive(Byte[], int, int, SocketFlags, AsyncCallback, object) method. InvalidOperationException Socket.EndReceive(IAsyncResult) was previously called for this operation. System.Net.Sockets.SocketException Note: For additional information on causes of the SocketException, see the System.Net.Sockets.SocketException class.ObjectDisposedException The current instance has been disposed.
The Socket.EndReceive(IAsyncResult) method completes the asynchronous read operation started in the Socket.BeginReceive(Byte[], int, int, SocketFlags, AsyncCallback, object) method.
Before calling Socket.BeginReceive(Byte[], int, int, SocketFlags, AsyncCallback, object), you need to create a callback method that implements the AsyncCallback delegate. This callback method executes in a separate thread and is called by the system after Socket.BeginReceive(Byte[], int, int, SocketFlags, AsyncCallback, object) returns. The callback method must accept the IAsyncResult returned by the Socket.BeginReceive(Byte[], int, int, SocketFlags, AsyncCallback, object) method as a parameter.
Within the callback method, call the IAsyncResult.AsyncState method of the IAsyncResult to obtain the state object passed to the Socket.BeginReceive(Byte[], int, int, SocketFlags, AsyncCallback, object) method. Extract the receiving System.Net.Sockets.Socket from this state object. After obtaining the System.Net.Sockets.Socket, you can call the Socket.EndReceive(IAsyncResult) method to successfully complete the read operation and return the number of bytes read.
The Socket.EndReceive(IAsyncResult) method will block until data is available. If you are using a connectionless protocol, Socket.EndReceive(IAsyncResult) will read the first enqueued datagram available in the incoming network buffer. If you are using a connection-oriented protocol, the Socket.EndReceive(IAsyncResult) method will read as much data as is available up to the number of bytes you specified in the size parameter of the Socket.BeginReceive(Byte[], int, int, SocketFlags, AsyncCallback, object) method. 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.EndReceive(IAsyncResult) method will complete immediately and return zero bytes.
To obtain the received data, call the IAsyncResult.AsyncState method of the IAsyncResult, and extract the buffer contained in the resulting state object.
To cancel a pending erload:System.Net.Sockets.Socket.BeginReceive, call the Socket.Close method.
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.
All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread exits before the operation completes.
This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].