public void Start() { dbHelper.Init(); IPEndPoint e = new IPEndPoint(IPAddress.Any, portNum); UdpClient u = new UdpClient(e); UdpState s = new UdpState(); s.e = e; s.u = u; u.BeginReceive(new AsyncCallback(recvCompletion), s); }
void recvCompletion(IAsyncResult ar) { UdpClient u = (UdpClient)((UdpState)(ar.AsyncState)).u; IPEndPoint e = (IPEndPoint)((UdpState)(ar.AsyncState)).e; Byte[] receiveBytes = u.EndReceive(ar, ref e); string receiveString = Encoding.ASCII.GetString(receiveBytes); OnRecv(receiveString); UdpState s = new UdpState(); s.e = e; s.u = u; u.BeginReceive(new AsyncCallback(recvCompletion), s); }