0
我正在使用下面的代碼讀取udp套接字,這很好。現在我需要將recv中的'received'傳回給主叫方。如何才能做到這一點。接受傳遞參數
try
{
client.BeginReceive(new AsyncCallback(recv), client);
}
private static void recv(IAsyncResult res)
{
try
{
UdpClient c = (UdpClient)(res.AsyncState);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 162);
byte[] received = c.EndReceive(res, ref RemoteIpEndPoint);
Console.WriteLine(ASCIIEncoding.ASCII.GetString(received));
c.BeginReceive(new AsyncCallback(recv), c);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
你不需要繞一個圈?據我可以看到,代碼將只捕獲一個數據包。 –