Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int         ListeningPort      = PRSCommunicator.DEFAULT_PORT;
            int         StartingClientPort = PRSCommunicator.DEFAULT_STARTING;
            int         EndingClientPort   = PRSCommunicator.DEFAULT_ENDING;
            int         Timeout            = PRSCommunicator.DEFAULT_TIMEOUT;
            PRSListener PRS = new PRSListener();

            if (args != null)
            {
                string[] command = args;

                for (int i = 0; i < command.Length; i = i + 2)
                {
                    switch (command[i].ToLower())
                    {
                    case "-p":
                        ListeningPort = Convert.ToInt32(command[i + 1]);
                        break;

                    case "-s":
                        StartingClientPort = Convert.ToInt32(command[i + 1]);
                        break;

                    case "-e":
                        EndingClientPort = Convert.ToInt32(command[i + 1]);
                        break;

                    case "-t":
                        Timeout = Convert.ToInt32(command[i + 1]);
                        break;
                    }
                }
                if (StartingClientPort > EndingClientPort)
                {
                    throw (new Exception("StartingPort larger than ending port"));
                }
                PRS.StartService(ListeningPort, StartingClientPort, EndingClientPort, Timeout);
            }

            else
            {
                PRS.StartService(ListeningPort, StartingClientPort, EndingClientPort, Timeout);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int         ListeningPort      = DEFAULT_PORT;
            int         StartingClientPort = DEFAULT_STARTING;
            int         EndingClientPort   = DEFAULT_ENDING;
            int         Timeout            = DEFAULT_TIMEOUT;
            PRSListener PRS = new PRSListener();
            bool        end = false;

            while (!end)
            {
                Console.WriteLine("Please Enter your Command");
                string   user_command = Console.ReadLine();
                string[] command      = user_command.Split();
                switch (command[0])
                {
                case "end":
                    end = true;
                    break;

                case "help":
                    Console.WriteLine("Use: prs\n options:\n -p <service port>\n -s < starting client port number >\n -e < ending client port number >\n -t < keep alive time in seconds >\n");
                    break;

                case "prs":    //if they want to start the service
                    try
                    {
                        for (int i = 1; i < command.Length; i = i + 2)
                        {
                            switch (command[i].ToLower())
                            {
                            case "-p":
                                ListeningPort = Convert.ToInt32(command[i + 1]);
                                break;

                            case "-s":
                                StartingClientPort = Convert.ToInt32(command[i + 1]);
                                break;

                            case "-e":
                                EndingClientPort = Convert.ToInt32(command[i + 1]);
                                break;

                            case "-t":
                                Timeout = Convert.ToInt32(command[i + 1]);
                                break;
                            }
                        }
                        if (StartingClientPort > EndingClientPort)
                        {
                            throw (new Exception("StartingPort larger than ending port"));
                        }
                        PRS.StartService(ListeningPort, StartingClientPort, EndingClientPort, Timeout);
                        break;
                    }
                    catch (Exception E)
                    {
                        Console.WriteLine("Exception occured:" + E);
                    }
                    break;

                default:
                    Console.WriteLine("Invalid Input");
                    break;
                }
            }
        }