UdpClient.EndReceive(IAsyncResult, IPEndPoint) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
보류 중인 비동기 수신을 끝냅니다.
public:
cli::array <System::Byte> ^ EndReceive(IAsyncResult ^ asyncResult, System::Net::IPEndPoint ^ % remoteEP);
public byte[] EndReceive(IAsyncResult asyncResult, ref System.Net.IPEndPoint? remoteEP);
public byte[] EndReceive(IAsyncResult asyncResult, ref System.Net.IPEndPoint remoteEP);
member this.EndReceive : IAsyncResult * IPEndPoint -> byte[]
Public Function EndReceive (asyncResult As IAsyncResult, ByRef remoteEP As IPEndPoint) As Byte()
매개 변수
- asyncResult
- IAsyncResult
IAsyncResult를 호출할 때 반환되는 BeginReceive(AsyncCallback, Object) 개체입니다.
- remoteEP
- IPEndPoint
지정된 원격 엔드포인트입니다.
반환
성공하면 데이터그램 데이터가 포함된 바이트 배열입니다.
예외
asyncResult
이(가) null
인 경우
BeginReceive(AsyncCallback, Object) 메서드를 호출했지만 asyncResult
가 반환되지 않은 경우
EndReceive(IAsyncResult, IPEndPoint)가 비동기 읽기를 위해 이미 호출된 경우
내부 Socket에 액세스하려고 시도하는 동안 오류가 발생한 경우.
내부 Socket이 닫힌 경우
예제
다음 코드 예제에서는 를 사용하여 BeginSend 서버 응답의 비동기 수신을 완료합니다.
public struct UdpState
{
public UdpClient u;
public IPEndPoint e;
}
public static bool messageReceived = false;
public static void ReceiveCallback(IAsyncResult ar)
{
UdpClient u = ((UdpState)(ar.AsyncState)).u;
IPEndPoint e = ((UdpState)(ar.AsyncState)).e;
byte[] receiveBytes = u.EndReceive(ar, ref e);
string receiveString = Encoding.ASCII.GetString(receiveBytes);
Console.WriteLine($"Received: {receiveString}");
messageReceived = true;
}
public static void ReceiveMessages()
{
// Receive a message and write it to the console.
IPEndPoint e = new IPEndPoint(IPAddress.Any, s_listenPort);
UdpClient u = new UdpClient(e);
UdpState s = new UdpState();
s.e = e;
s.u = u;
Console.WriteLine("listening for messages");
u.BeginReceive(new AsyncCallback(ReceiveCallback), s);
// Do some work while we wait for a message. For this example, we'll just sleep
while (!messageReceived)
{
Thread.Sleep(100);
}
}
설명
이 메서드는 작업이 완료될 때까지 차단합니다.
이 작업을 동기적으로 수행하려면 메서드를 Receive 사용합니다.