public void run()
            {
                try{
                //setup server
                server  = new BoggleServer(80, "dictionary.txt");

                //setup client
                BoggleClientModel target = new BoggleClientModel();
                string IPAddress = "garbageAddress";
                string name = "test";

                target.noSuchHostEvent += delegate(string line)
                {
                    MRE.Set();
                };

                //trigger event
                target.Connect(IPAddress, name);

                Assert.AreEqual(true, MRE.WaitOne(timeout), "Timed out waiting 1");
                }
                finally
                {server.close();}
            }
            public void run()
            {
                try
                {
                    //setup server
                    server = new BoggleServer(10, "dictionary.txt");

                    //setup clients
                    BoggleClientModel target = new BoggleClientModel();
                    string IPAddress = "127.0.0.1";
                    string name = "test";

                    BoggleClientModel target2 = new BoggleClientModel();
                    string name2 = "test2";

                    target.IncomingTimeEvent += delegate(string line)
                    {
                        MRE.Set();
                    };

                    target2.IncomingTimeEvent += delegate(string line)
                    {
                        MRE1.Set();
                    };

                    //connect the clients
                    target.Connect(IPAddress, name);
                    target2.Connect(IPAddress, name2);

                    //trigger event
                    Thread.Sleep(1000);

                    Assert.AreEqual(true, MRE.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual(true, MRE1.WaitOne(timeout), "Timed out waiting 2");
                }
                finally
                {
                    server.close();
                }
            }
示例#3
0
        /// <summary>
        /// Main method called upon when the user runs this program. Here we will initialize a 
        /// new BoggleServer with the command line args and run the server.
        /// </summary>
        public static void Main(string[] args)
        {
            // If the user supplied less than two args or more than three,
            // then print an error message and terminate.
            if (args.Length < 2 || args.Length > 3)
            {
                Console.WriteLine("Error: Invalid arguments.");
                Console.WriteLine("usage: BoggleServer time dictionary_path optional_string");
                Console.WriteLine("Wrong Number of Args");
                return;
            }

            // Otherwise the user must have provided the correct number of
            // arguments. Continue forward..

            // Parse the arguments and ensure that they are valid. If they are not, then
            // print a descriptive error message and terminate the program.

            // If the first argument wasn't an integer, then print an error message
            // and terminate.
            int GameLength = 0;
            if (!int.TryParse(args[0], out GameLength) || GameLength <= 0)
            {
                Console.WriteLine("Error: Invalid arguments.");
                Console.WriteLine("usage: BoggleServer time dictionary_path optional_string");
                Console.WriteLine("--> time must be a positive integer.");
                return;
            }

            // At this point, the first argument must be an integer value. Continue parsing the
            // remaining arguments..

            // If the second argument (the filepath) wasn't a valid filepath, then print an error
            // message and terminate.
            if (!File.Exists(args[1]))
            {
                Console.WriteLine("Error: You must provide a valid file path!");
                return;
            }

            // If there was a third argument, then it must be atleast 16 characters and it must only
            // contains letters.
            if (args.Length == 3 && (args[2].Length != 16 || !args[2].All(Char.IsLetter)))
            {
                args[2].All(Char.IsLetter);
                Console.WriteLine("Error: Invalid arguments.");
                Console.WriteLine("usage: BoggleServer time dictionary_path optional_string");
                Console.WriteLine("--> optional_string must be 16 characters.");
                return;
            }

            // After paramter validation, start the Boggle game server.
            BoggleServer GameServer;
            if (args.Length == 2)
                GameServer = new BoggleServer(GameLength, args[1], null);
            else
                GameServer = new BoggleServer(GameLength, args[1], args[2]);

            Console.Read();
        }