Ejemplo n.º 1
0
 public void ReceiveInfo(string ip = "")
 {
     ThreadPool.QueueUserWorkItem((x) =>
     {
         try
         {
             Socket sock    = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
             IPEndPoint iep = null;
             if (ip.Equals(""))
             {
                 iep = new IPEndPoint(IPAddress.Any, IP_PORT);
             }
             else
             {
                 iep = new IPEndPoint(IPAddress.Parse(ip), IP_PORT);
             }
             sock.Bind(iep);
             EndPoint ep = (EndPoint)iep;
             byte[] data;
             int recv;
             string stringData;
             while (connecting)
             {
                 data       = new byte[1024];
                 recv       = sock.ReceiveFrom(data, ref ep);
                 stringData = Encoding.ASCII.GetString(data, 0, recv);
                 RD.Invoke(stringData);
             }
             sock.Close();
         }
         catch (Exception err)
         {
         }
     });
 }