예제 #1
0
파일: UdpHandler.cs 프로젝트: Ieaun/Diss
        public void Start()
        {
            _logger.LogInformation("Starting Udp Handler");
            _endpoint = new UdpEndpoint("192.168.8.100", 30098);
            _endpoint.EndpointDetected += EndpointDetected;


            _endpoint.DatagramReceived += DatagramReceived;
            _endpoint.StartServer();
        }
예제 #2
0
파일: UdpHandler.cs 프로젝트: Ieaun/Diss
 public void Start()
 {
     for (int i = 0; i < 5; i++)
     {
         try
         {
             _endPoint.StartServer();
             _logger.LogInformation("LoRaWAN Pipeline UDP server started");
             return;
         }
         catch (Exception e)
         {
             _logger.LogError("failed to start to UDP server, retrying {x}/{y}", i + 1, 5);
             System.Threading.Thread.Sleep(i * 1000);
         }
     }
 }
예제 #3
0
        static void Main(string[] args)
        {
            /*
             *
             *
             * Usage:
             *    node 127.0.0.1 8000
             *
             * Starts the endpoint on IP address 127.0.0.1 port 8000.
             *
             *
             *
             */

            _Ip   = args[0];
            _Port = Convert.ToInt32(args[1]);

            _UdpEndpoint = new UdpEndpoint(_Ip, _Port);
            _UdpEndpoint.EndpointDetected += EndpointDetected;
            _UdpEndpoint.DatagramReceived += DatagramReceived;
            _UdpEndpoint.StartServer();

            while (true)
            {
                Console.Write("[" + _Ip + ":" + _Port + " Command/? for help]: ");
                string userInput = Console.ReadLine();
                if (String.IsNullOrEmpty(userInput))
                {
                    continue;
                }

                if (userInput.Equals("?"))
                {
                    Menu();
                }
                else if (userInput.Equals("q"))
                {
                    break;
                }
                else if (userInput.Equals("cls"))
                {
                    Console.Clear();
                }
                else if (userInput.Equals("list"))
                {
                    List <string> recents = _UdpEndpoint.Endpoints;
                    if (recents != null)
                    {
                        Console.WriteLine("Recent endpoints");
                        foreach (string endpoint in recents)
                        {
                            Console.WriteLine("  " + endpoint);
                        }
                    }
                    else
                    {
                        Console.WriteLine("None");
                    }
                }
                else
                {
                    string[] parts = userInput.Split(new char[] { ' ' }, 2);
                    if (parts.Length != 2)
                    {
                        continue;
                    }

                    string msg        = parts[1];
                    string ipPort     = parts[0];
                    int    colonIndex = parts[0].LastIndexOf(':');
                    string ip         = ipPort.Substring(0, colonIndex);
                    int    port       = Convert.ToInt32(ipPort.Substring(colonIndex + 1));

                    _UdpEndpoint.Send(ip, port, msg);
                }
            }

            Console.ReadLine();
        }