public void Init() { #region UDP IPEndPoint e = new IPEndPoint(IPAddress.Any, 3000); UdpClient udp = new UdpClient(e); UdpState s = new UdpState(); s.e = e; s.u = udp; udp.BeginReceive(new AsyncCallback(UDPReceive), s); #endregion }
public void UDPReceive(IAsyncResult ar) { try { UdpClient u = (UdpClient)((UdpState)(ar.AsyncState)).u; IPEndPoint e = (IPEndPoint)((UdpState)(ar.AsyncState)).e; Byte[] receiveBytes = u.EndReceive(ar, ref e); UdpState s = new UdpState(); s.e = e; s.u = u; if (receiveBytes.Length == 72) { Decompose(receiveBytes); } u.BeginReceive(new AsyncCallback(UDPReceive), s); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } }