System.Net.Sockets.UdpClient.ReceiveAsync Method

Returns a UDP datagram asynchronously that was sent by a remote host.

Syntax

public System.Threading.Tasks.Task<UdpReceiveResult> ReceiveAsync ()

Returns

Returns System.Threading.Tasks.Task`1.

The task object representing the asynchronous operation.

Remarks

This operation will not block. The returned System.Threading.Tasks.Task`1> object will complete after the UDP packet has been received.

If you specify a default remote host in the UdpClient.Connect(string, int) method, this method will accept datagrams from that host only. All other datagrams will be discarded.

If you receive a System.Net.Sockets.SocketException, use SocketException.ErrorCode to obtain the specific error code. Once you have obtained this code, you can refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error.

Note:

If you intend to receive multicasted datagrams, do not call the UdpClient.Connect(string, int) method prior to calling this method. The System.Net.Sockets.UdpClient you use to receive datagrams must be created using the multicast port number.

Requirements

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