UdpClient.ReceiveAsync UdpClient.ReceiveAsync UdpClient.ReceiveAsync UdpClient.ReceiveAsync Method

定義

非同步傳回由遠端主機傳送的 UDP 資料包。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)

傳回

工作物件,表示非同步作業。The task object representing the asynchronous operation.

例外狀況

存取通訊端時發生錯誤。An error occurred when accessing the socket.

備註

這項作業不會封鎖。This operation will not block. 傳回Task<TResult>的 > 物件將會在收到 UDP 封包之後完成。The returned Task<TResult>> object will complete after the UDP packet has been received.

如果您在Connect方法中指定預設遠端主機, 這個方法只會接受來自該主機的資料包。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.

如果您收到SocketException, 請使用SocketException.ErrorCode來取得特定的錯誤碼。If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code. 取得此程式碼之後, 您可以參考Windows socket 第2版 API 錯誤碼檔, 以取得錯誤的詳細描述。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.

警告

如果您想要接收多播的資料包, 請不要Connect在呼叫這個方法之前呼叫方法。If you intend to receive multicasted datagrams, do not call the Connect method prior to calling this method. UdpClient用來接收資料包的必須使用多播埠號碼來建立。The UdpClient you use to receive datagrams must be created using the multicast port number.

適用於