예제 #1
0
        void BuildListenerConsole()
        {
            SockFactoryOptions options = new SockFactoryOptions();

            // collect config
            Console.WriteLine("[Build Listener]");
            Console.WriteLine("1. TCP Server");
            Console.WriteLine("2. UDP Server");

            Console.Write("> ");
            string sel = Console.ReadLine();

            Console.WriteLine("Enter listening IP address (leave blank for 0.0.0.0)");
            Console.Write("> ");
            string localIpAddr = Console.ReadLine();

            if (localIpAddr == "")
            {
                localIpAddr = "0.0.0.0";
            }
            Console.WriteLine("Enter server port (leave blank for 11000)");
            Console.Write("> ");
            string localPortStr = Console.ReadLine();
            int    localPort;

            if (localPortStr == "")
            {
                localPort = 11000;
            }
            else
            {
                try
                {
                    localPort = int.Parse(localPortStr);
                }
                catch (FormatException)
                {
                    Console.WriteLine("[Error] Invalid Input");
                    return;
                }
            }
            try
            {
                options.ListenerIpAddress = IPAddress.Parse(localIpAddr);
            }
            catch (FormatException)
            {
                Console.WriteLine("[Error] Invalid Input");
                return;
            }
            options.ListenerPort    = localPort;
            options.ProtocolFactory = new Protocol.DefaultProtocolFactory(_protocolOptions);
            // begin to build
            switch (sel)
            {
            case "1":
                _sockController.BeginBuildTcp(options, SocketRole.Listener);
                break;

            case "2":
                // TODO
                break;

            default:
                break;
            }
        }