我正在使用以下代码从 udp 套接字读取数据,该代码运行良好。现在我需要将'received'从recv传回调用main。如何才能做到这一点。
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);
}
}