Exemple #1
0
 private static void ListenSockets()
 {
     lock (global::SIPLib.Listener.LockListen)
     {
         global::System.Net.Sockets.UdpClient receivingUdpClient = new global::System.Net.Sockets.UdpClient(global::SIPLib.Listener.port);
         try
         {
             global::System.Net.IPEndPoint RemoteIpEndPoint = new global::System.Net.IPEndPoint(global::System.Net.IPAddress.Any, 0);
             while (true)
             {
                 byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
                 global::SIPLib.Listener.WatchInfo(receiveBytes);
                 if (global::SIPLib.Listener.StopFlag == true)
                 {
                     break;
                 }
             }
         }
         catch
         {
             receivingUdpClient.Close();
             return;
         }
         receivingUdpClient.Close();
     }
 }
Exemple #2
0
 private bool SendSocket(string ToIP, int port, byte[] sendBytes)
 {
     global::System.Net.IPAddress         ipAddress;
     global::System.Net.Sockets.UdpClient udpClient = new global::System.Net.Sockets.UdpClient();
     if (!System.Net.IPAddress.TryParse(ToIP, out ipAddress))
     {
         return(false);
     }
     ;
     global::System.Net.IPEndPoint ipEndPoint = new global::System.Net.IPEndPoint(ipAddress, port);
     try { udpClient.Send(sendBytes, sendBytes.Length, ipEndPoint); } catch { return(false); }
     return(true);
 }
Exemple #3
0
 private bool SendSocket(string ToIP, int port, string Info)
 {
     global::System.Net.Sockets.UdpClient udpClient = new global::System.Net.Sockets.UdpClient();
     byte[] sendBytes = global::System.Text.Encoding.ASCII.GetBytes(Info);
     global::System.Net.IPAddress ipAddress = null;
     if (!System.Net.IPAddress.TryParse(ToIP, out ipAddress))
     {
         return(false);
     }
     ;
     global::System.Net.IPEndPoint ipEndPoint = new global::System.Net.IPEndPoint(ipAddress, port);
     try { udpClient.Send(sendBytes, sendBytes.Length, ipEndPoint); }
     catch { return(false); }
     return(true);
 }
Exemple #4
0
 private void DataReceive()
 {
     lock (this.LockReceive)
     {
         global::System.Net.Sockets.UdpClient receivingUdpClient = new global::System.Net.Sockets.UdpClient(this._portReceive);
         global::System.Net.IPAddress         ipAddress;
         global::System.Net.IPAddress.TryParse(this._ToIP, out ipAddress);
         try
         {
             global::System.Net.IPEndPoint RemoteIpEndPoint = new global::System.Net.IPEndPoint(ipAddress, this._portReceive);
             while (true)
             {
                 byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
                 this.DataArrived(receiveBytes, receiveBytes.Length);
             }
         } catch { /* NOTHING */ }
     }
 }
Exemple #5
0
 private bool SendInfo(string Info)
 {
     global::System.Net.IPAddress         ipAddress;
     global::System.Net.Sockets.UdpClient udpClient = new global::System.Net.Sockets.UdpClient();
     byte[] sendBytes = global::System.Text.Encoding.ASCII.GetBytes(Info);
     if (global::System.Net.IPAddress.TryParse(ToIP, out ipAddress))
     {
         try { udpClient.Send(sendBytes, sendBytes.Length, new global::System.Net.IPEndPoint(ipAddress, port)); } catch { return(false); }
     }
     else
     {
         global::System.Net.IPAddress[] ips = global::System.Net.Dns.GetHostAddresses(ToIP);
         foreach (global::System.Net.IPAddress ip in ips)
         {
             try { udpClient.Send(sendBytes, sendBytes.Length, new global::System.Net.IPEndPoint(ip, port)); } catch { return(false); }
         }
         if (ips.Length == 0)
         {
             return(false);
         }
     };
     return(true);
 }