Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        private void Run()
        {
            while (!stop)
            {
                PrintMenu();
                string choice = Console.ReadLine();

                try
                {
                    switch (choice)
                    {
                    case "1":
                        AddPlane();
                        break;

                    case "2":
                        PrintPlanes();
                        break;

                    case "3":
                        PrintTypes();
                        break;

                    case "4":

                        PrintPlanes();
                        FlyPlanes();
                        break;

                    case "0":
                        stop = true;
                        break;

                    default:
                        Console.WriteLine("No such choice");
                        break;
                    }
                    Console.WriteLine();
                }
                catch (Exception e)
                {
                    NotifyException?.Invoke(e);
                }
            }
        }