Пример #1
0
 public Connection(IPAddress Ip, int port)
 {
     InitializeComponent();
     setEvents();
     clientGT = new ClientGestTopics(port, Ip);
     clientGT.connect();
 }
Пример #2
0
        public Connexion(IPAddress Ip, int port)
        {
            InitializeComponent();
            clientGT = new ClientGestTopics(Ip, port);
            Thread test1 = new Thread(new ThreadStart(clientGT.connect));

            test1.Start();
        }
Пример #3
0
        public static void Main()
        {
            IPHostEntry ipHostEntry = Dns.GetHostEntry(Dns.GetHostName());
            IPAddress   ipAddress   = ipHostEntry.AddressList[0];

            ClientGestTopics cgt = new ClientGestTopics();

            cgt.setServer(ipAddress, 2300);
            cgt.connect();
            Console.WriteLine(cgt.createTopic("Test topic"));
            Chatroom c = cgt.joinTopic("Test topic");

            Console.WriteLine(cgt.listTopics().ToString());
        }
Пример #4
0
        public ChatWindow(string pseudo, ClientGestTopics clientGT)
        {
            /***Connect the client***/
            this.clientGT = clientGT;
            textDisplay   = new TextBox();
            sendText      = new TextBox();
            chatter       = new TextChatter(pseudo);


            /**Set up the GUI **/
            InitializeComponent();
            setEvents();

            /*Set up the topics that already exist*/
            setTopics();
        }
Пример #5
0
        public static void test()
        {
            IPAddress Ip   = IPAddress.Parse("127.0.0.1");
            int       port = 55555;

            ServerGestTopics         server = new ServerGestTopics(Ip);
            ParameterizedThreadStart ts     = new ParameterizedThreadStart(server.startServer);
            Thread t = new Thread(ts);

            t.Start(port);

            ClientGestTopics client1 = new ClientGestTopics(port, Ip);
            Thread           test1   = new Thread(new ThreadStart(client1.connect));

            test1.Start();


            ClientGestTopics client2 = new ClientGestTopics(port, Ip);
            Thread           test2   = new Thread(new ThreadStart(client2.connect));

            test2.Start();

            client1.createTopic("Ruby");
            client1.createTopic("Java");
            client2.createTopic("PHP");

            Console.WriteLine(client1.listTopics());
            ClientChatRoom cr1 = (ClientChatRoom)client1.joinTopic("PHP");
            ClientChatRoom cr2 = (ClientChatRoom)client2.joinTopic("PHP");

            TextChatter bob = new TextChatter("bob");
            TextChatter joe = new TextChatter("joe");


            cr1.join(bob);
            cr1.post("Je suis seul ou quoi ?", bob);
            cr2.join(joe);
            cr1.post("Tiens, salut Bob !", bob);
            cr2.post("Yop", joe);
            cr1.receiveMessages();
            // cr1.quit(bob);
            cr2.post("Toi aussi tu chat sur les forums de jeux pendant les TP,Bob ?", joe);
        }
Пример #6
0
    public static void test()
    {
        IPAddress Ip = IPAddress.Parse("127.0.0.1");
        int port = 55555;

        ServerGestTopics server = new ServerGestTopics(Ip);
        ParameterizedThreadStart ts = new ParameterizedThreadStart(server.startServer);
        Thread t = new Thread(ts);
        t.Start(port);

        ClientGestTopics client1 = new ClientGestTopics(Ip, port);
        Thread test1 = new Thread(new ThreadStart(client1.connect));
        test1.Start();

        ClientGestTopics client2 = new ClientGestTopics(Ip, port);
        Thread test2 = new Thread(new ThreadStart(client2.connect));
        test2.Start();

        try
        {
            client1.addUser("bob", "123");
            Console.WriteLine("Bob has been added !");
            client1.removeUser("bob");
            Console.WriteLine("Bob has been removed !");
            client1.removeUser("bob");
            Console.WriteLine("Bob has been removes twice !");
        }
        catch (UserUnknownException e)
        {
            Console.WriteLine(e.login + " : user unknown (enable to remove)!");
        }
        catch (UserExistsException e)
        {
            Console.WriteLine(e.login + " has already been added !");
        }

        // authentification

        try
        {
            client1.addUser("bob", "123");
            Console.WriteLine("Bob has been added !");
            client2.authentify("bob", "123");
            Console.WriteLine("Authentification OK !");
            client2.authentify("bob", "456");
            Console.WriteLine("Invalid password !");
        }
        catch (WrongPasswordException e)
        {
            Console.WriteLine(e.login + " has provided an invalid password !");
        }
        catch (UserExistsException e)
        {
            Console.WriteLine(e.login + " has already been added !");
        }
        catch (UserUnknownException e)
        {
            Console.WriteLine(e.login + " : user unknown (enable to remove)!");
        }

        // persistance
        try
        {
            server.save("users.txt");
            AuthentificationManager am1 = new Authentification();
            am1.load("users.txt");
            am1.authentify("bob", "123");
            Console.WriteLine("Loading complete !");
        }
        catch (UserUnknownException e)
        {
            Console.WriteLine(e.login + " is unknown ! error during the saving/loading.");
        }
        catch (WrongPasswordException e)
        {
            Console.WriteLine(e.login + " has provided an invalid password !error during the saving/loading.");
        }
        catch (UserExistsException e)
        {
            Console.WriteLine(e.login + " has already been added !error during the saving/loading.");
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }

            client1.createTopic("Ruby");
            client1.createTopic("Java");
            client2.createTopic("PHP");
            Console.WriteLine("Topics list : " + client1.listTopics());

            IChatroom cr2 = client2.joinTopic("PHP");
            IChatroom cr1 = client1.joinTopic("PHP");

            IChatter bob = new TextChatter("Bob");
            IChatter joe = new TextChatter("Joe");

            cr1.join(bob);
            cr1.post("Je suis seul ou quoi ?", bob);
            cr2.join(joe);
            cr1.post("Tiens, salut Bob !", bob);
            cr2.post("Yop", joe);
            cr1.quit(bob);
            cr2.post("Toi aussi tu chat sur les forums de jeux pendant les TP,Bob ?", joe);
    }
Пример #7
0
    public static void test()
    {
        IPAddress Ip   = IPAddress.Parse("127.0.0.1");
        int       port = 55555;

        ServerGestTopics         server = new ServerGestTopics(Ip);
        ParameterizedThreadStart ts     = new ParameterizedThreadStart(server.startServer);
        Thread t = new Thread(ts);

        t.Start(port);

        ClientGestTopics client1 = new ClientGestTopics(Ip, port);
        Thread           test1   = new Thread(new ThreadStart(client1.connect));

        test1.Start();


        ClientGestTopics client2 = new ClientGestTopics(Ip, port);
        Thread           test2   = new Thread(new ThreadStart(client2.connect));

        test2.Start();


        try
        {
            client1.addUser("bob", "123");
            Console.WriteLine("Bob has been added !");
            client1.removeUser("bob");
            Console.WriteLine("Bob has been removed !");
            client1.removeUser("bob");
            Console.WriteLine("Bob has been removes twice !");
        }
        catch (UserUnknownException e)
        {
            Console.WriteLine(e.login + " : user unknown (enable to remove)!");
        }
        catch (UserExistsException e)
        {
            Console.WriteLine(e.login + " has already been added !");
        }



        // authentification

        try
        {
            client1.addUser("bob", "123");
            Console.WriteLine("Bob has been added !");
            client2.authentify("bob", "123");
            Console.WriteLine("Authentification OK !");
            client2.authentify("bob", "456");
            Console.WriteLine("Invalid password !");
        }
        catch (WrongPasswordException e)
        {
            Console.WriteLine(e.login + " has provided an invalid password !");
        }
        catch (UserExistsException e)
        {
            Console.WriteLine(e.login + " has already been added !");
        }
        catch (UserUnknownException e)
        {
            Console.WriteLine(e.login + " : user unknown (enable to remove)!");
        }


        // persistance
        try
        {
            server.save("users.txt");
            AuthentificationManager am1 = new Authentification();
            am1.load("users.txt");
            am1.authentify("bob", "123");
            Console.WriteLine("Loading complete !");
        }
        catch (UserUnknownException e)
        {
            Console.WriteLine(e.login + " is unknown ! error during the saving/loading.");
        }
        catch (WrongPasswordException e)
        {
            Console.WriteLine(e.login + " has provided an invalid password !error during the saving/loading.");
        }
        catch (UserExistsException e)
        {
            Console.WriteLine(e.login + " has already been added !error during the saving/loading.");
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }


        client1.createTopic("Ruby");
        client1.createTopic("Java");
        client2.createTopic("PHP");
        Console.WriteLine("Topics list : " + client1.listTopics());


        IChatroom cr2 = client2.joinTopic("PHP");
        IChatroom cr1 = client1.joinTopic("PHP");

        IChatter bob = new TextChatter("Bob");
        IChatter joe = new TextChatter("Joe");

        cr1.join(bob);
        cr1.post("Je suis seul ou quoi ?", bob);
        cr2.join(joe);
        cr1.post("Tiens, salut Bob !", bob);
        cr2.post("Yop", joe);
        cr1.quit(bob);
        cr2.post("Toi aussi tu chat sur les forums de jeux pendant les TP,Bob ?", joe);
    }