Exemplo n.º 1
0
 public void Send(string message)
 {
     _endpoint.Send("192.168.8.100", 30099, message);
 }
Exemplo n.º 2
0
 public void Send(string address, int port, string message)
 {
     _endPoint.Send(address, port, message);
 }
Exemplo n.º 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();
        }