System.Net.Sockets.Socket.BeginReceiveFrom Method
Begins an asynchronous operation to receive data from a socket and, for connectionless protocols, store the endpoint associated with the socket that sent the data.

Syntax

public IAsyncResult BeginReceiveFrom (byte[] buffer, int offset, int size, SocketFlags socket_flags, ref System.Net.EndPoint remote_end, AsyncCallback callback, object state)

Parameters

buffer
A byte array to store data received from the socket.
offset
A int containing the zero-based position in buffer to begin storing the received data.
size
A int containing the number of bytes to receive.
socket_flags
Documentation for this section has not yet been entered.
remote_end
Documentation for this section has not yet been entered.
callback
A AsyncCallback delegate, or null.
state
An application-defined object, or null.

Returns

A IAsyncResult instance that contains information about the asynchronous operation.

Exceptions

TypeReason
ArgumentNullException

buffer is null.

-or-

remoteEP is null.

ArgumentOutOfRangeException

offset < 0.

-or-

offset > buffer.Length.

-or-

size < 0.

-or-

size > buffer.Length - offset.

System.Net.Sockets.SocketException

socketFlags is not a valid combination of values.

-or-

An error occurred while accessing the socket.

Note: For additional information on causes of the SocketException, see the System.Net.Sockets.SocketException class.

ObjectDisposedExceptionThe current instance has been disposed.
System.Security.SecurityExceptionA caller in the call stack does not have the required permissions.

Remarks

To retrieve the results of the operation and release resources allocated by the Socket.BeginReceiveFrom(Byte[], int, int, SocketFlags, System.Net.EndPoint@, AsyncCallback, object) method, call the Socket.EndReceiveFrom(IAsyncResult, System.Net.EndPoint@) method, and specify the IAsyncResult object returned by this method.

Note: The Socket.EndReceiveFrom(IAsyncResult, System.Net.EndPoint@) method should be called exactly once for each call to the Socket.BeginReceiveFrom(Byte[], int, int, SocketFlags, System.Net.EndPoint@, AsyncCallback, object) method.

If the callback parameter is not null, the method referenced by callback is invoked when the asynchronous operation completes. The IAsyncResult object returned by this method is passed as the argument to the method referenced by callback. The method referenced by callback can retrieve the results of the operation by calling the Socket.EndReceiveFrom(IAsyncResult, System.Net.EndPoint@) method.

The state parameter can be any object that the caller wishes to have available for the duration of the asynchronous operation. This object is available via the IAsyncResult.AsyncState property of the object returned by this method.

Note:

For more information, see Socket.ReceiveFrom(Byte[], int, int, SocketFlags, System.Net.EndPoint@), the synchronous version of this method.

Permissions

TypeReason
System.Net.SocketPermission

Requires permission to accept a connection on the endpoint defined by the Socket.LocalEndPoint property of the current instance. See System.Net.NetworkAccess.Accept.

Requires permission to make a connection to the endpoint defined by remoteEP. See System.Net.NetworkAccess.Connect.

Example

For an outline of an asynchronous operation, see the Socket.BeginAccept(AsyncCallback, object) method. For the complete example, see System.Net.Sockets.Socket.

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0