Upraviť

Zdieľať cez


UdpClient.ReceiveAsync Method

Definition

Overloads

ReceiveAsync()

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

ReceiveAsync(CancellationToken)

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

ReceiveAsync()

Source:
UDPClient.cs
Source:
UDPClient.cs
Source:
UDPClient.cs

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

public:
 System::Threading::Tasks::Task<System::Net::Sockets::UdpReceiveResult> ^ ReceiveAsync();
public System.Threading.Tasks.Task<System.Net.Sockets.UdpReceiveResult> ReceiveAsync ();
member this.ReceiveAsync : unit -> System.Threading.Tasks.Task<System.Net.Sockets.UdpReceiveResult>
Public Function ReceiveAsync () As Task(Of UdpReceiveResult)

Returns

The task object representing the asynchronous operation.

Exceptions

The underlying Socket has been closed.

An error occurred when accessing the socket.

Remarks

This operation will not block. The returned Task<TResult>> object will complete after the UDP packet has been received.

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

If you receive a 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 for a detailed description of the error.

Warning

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

Applies to

ReceiveAsync(CancellationToken)

Source:
UDPClient.cs
Source:
UDPClient.cs
Source:
UDPClient.cs

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

public:
 System::Threading::Tasks::ValueTask<System::Net::Sockets::UdpReceiveResult> ReceiveAsync(System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.ValueTask<System.Net.Sockets.UdpReceiveResult> ReceiveAsync (System.Threading.CancellationToken cancellationToken);
member this.ReceiveAsync : System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<System.Net.Sockets.UdpReceiveResult>
Public Function ReceiveAsync (cancellationToken As CancellationToken) As ValueTask(Of UdpReceiveResult)

Parameters

cancellationToken
CancellationToken

The token to monitor for cancellation requests.

Returns

A ValueTask<TResult> representing the asynchronous operation.

Exceptions

The underlying Socket has been closed.

An error occurred when accessing the socket.

The cancellation token was canceled. This exception is stored into the returned task.

Applies to