MSDN gives this code as an example to create a callback function for
UdpClient.Begin Receive. It doesn't compile because the compiler does
not recognize "UdpState". I can't find any info on it either. Does
anyone know what "UdpState" is or could you point me to some sample
code on how to properly implement a ReceiveCallback function? Any help
would be appreciated.
public static bool messageReceived = false;
public static void ReceiveCallback (IAsyncResult ar)
{
UdpClient u = (UdpClient)((Ud pState)(ar.Asyn cState)).u;
IPEndPoint e = (IPEndPoint)((U dpState)(ar.Asy ncState)).e;
Byte[] receiveBytes = u.EndReceive(ar , ref e);
string receiveString = Encoding.ASCII. GetString(recei veBytes);
Console.WriteLi ne("Received: {0}", receiveString);
messageReceived = true;
}
MSDN link:
ms-help://MS.MSDN.vAug06. en/cpref10/html/M_System_Net_So ckets_UdpClient _BeginReceive_1 _2bb042b2.htm
UdpClient.Begin Receive. It doesn't compile because the compiler does
not recognize "UdpState". I can't find any info on it either. Does
anyone know what "UdpState" is or could you point me to some sample
code on how to properly implement a ReceiveCallback function? Any help
would be appreciated.
public static bool messageReceived = false;
public static void ReceiveCallback (IAsyncResult ar)
{
UdpClient u = (UdpClient)((Ud pState)(ar.Asyn cState)).u;
IPEndPoint e = (IPEndPoint)((U dpState)(ar.Asy ncState)).e;
Byte[] receiveBytes = u.EndReceive(ar , ref e);
string receiveString = Encoding.ASCII. GetString(recei veBytes);
Console.WriteLi ne("Received: {0}", receiveString);
messageReceived = true;
}
MSDN link:
ms-help://MS.MSDN.vAug06. en/cpref10/html/M_System_Net_So ckets_UdpClient _BeginReceive_1 _2bb042b2.htm
Comment