コード例 #1
0
 public SipUA(SipUA o)
 {
     user  = o.user;
     ip    = o.ip;
     port  = o.port;
     radio = o.radio;
 }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="remote_ua"></param>
        /// <returns></returns>
        public bool SipPing(SipUA remote_ua)
        {
            using (UdpClient udpClient = new UdpClient(/*local_ua.port ?? 5060*/ 0))
            {
                // Actualizo el puerto local al seleccionado por la pila....
                SipUA working_local_ua = new SipUA(local_ua);
                working_local_ua.port = ((IPEndPoint)udpClient.Client.LocalEndPoint).Port;

                udpClient.Client.ReceiveTimeout = timeout;

                var    to   = new IPEndPoint(IPAddress.Parse(remote_ua.ip), remote_ua.port ?? 5060);
                byte[] data = Encoding.ASCII.GetBytes(
                    (new SipOptionsRequest()
                {
                    from = working_local_ua,
                    to = remote_ua,
                    CSeq = cseq.ToString("00000000")
                }).Message);
                cseq++;
                try
                {
                    IPEndPoint remoteEP = null;
                    udpClient.Client.ReceiveTimeout = timeout;

                    while (udpClient.Available > 0)
                    {
                        udpClient.Receive(ref remoteEP);
                    }

                    udpClient.Send(data, data.Length, to);
                    byte[] receivedData = udpClient.Receive(ref remoteEP);
                    remote_ua.last_response = new SipResponse(receivedData);
                    return(true);
                }
                catch (SocketException x)
                {
                    NotifyException?.Invoke(remote_ua, x);
                    remote_ua.last_response = new SipResponse(null);
                    return(x.SocketErrorCode == SocketError.TimedOut ? false : true);
                }
                catch (Exception x)
                {
                    NotifyException?.Invoke(remote_ua, x);
                    remote_ua.last_response = new SipResponse(null);
                }
            }
            return(true);
        }
コード例 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="UA"></param>
 /// <param name="Timeout"></param>
 public SipSupervisor(SipUA UA, int Timeout = 500)
 {
     local_ua = UA;
     timeout  = Timeout;
     cseq     = 1;
 }