static void Main(string[] args) { // Test de base de l'échange de messages entre serveur/client ClientTopicsManager client = new ClientTopicsManager(); try { client.setServer("127.0.0.1", 2453); client.connect(); client.createTopic("topic 1"); client.createTopic("topic 2"); List <String> topics = client.listTopics(); Console.WriteLine("The openned topics are : "); foreach (String topic in topics) { Console.WriteLine(topic); } Chatroom chatroom = client.joinTopic("topic 2"); Chatter chatter = new TextChatter("bob", "123"); chatroom.join(chatter); chatroom.post("nouveau message", chatter); Thread.Sleep(10000); chatroom.quit(chatter); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public chatForm(int port, string usernme) { InitializeComponent(); DuplexChannelFactory<Chatroom> dupFactory = null; TextChatter _chatter = new TextChatter(this); dupFactory = new DuplexChannelFactory<Chatroom>( _chatter, new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:" + port + "/Chat")); dupFactory.Open(); clientProxy = dupFactory.CreateChannel(); username = usernme; clientProxy.join(username); }
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); }
public static void Main() { Chatter bob = new TextChatter("Bob"); Chatter joe = new TextChatter("Joe"); TopicsManager gt = new TextGestTopics(); gt.createTopic("java"); gt.createTopic("UML"); gt.listTopics(); gt.createTopic("jeux"); gt.listTopics(); Chatroom cr = gt.joinTopic("jeux"); cr.join(bob); cr.post("Je suis seul ou quoi ?", bob); cr.join(joe); cr.post("Tiens, salut Joe !", bob); cr.post("Toi aussi tu chat sur les forums de jeux pendant les TP, Bob ? ", joe); }
public override void gereClient() { try { Message inputMessage; while ((inputMessage = getMessage()) != null) { //Message inputMessage = getMessage(); switch (inputMessage.getHead()) { case Header.Join: pseudo = inputMessage.getData()[0]; textChatroom.join(this); break; case Header.Post: String message = inputMessage.getData()[1]; textChatroom.post(message, this); break; case Header.Quit: Chatter c = new TextChatter(inputMessage.getData()[0]); textChatroom.quit(c); break; default: break; } } } catch (Exception e) { Console.WriteLine(e); } }
static void Main(string[] args) { Chatter bob = new TextChatter("Bob"); Chatter joe = new TextChatter("Joe"); TopicsManager gt = new TextGestTopics(); gt.CreateTopic("java"); gt.CreateTopic("UML"); gt.ListTopics(); gt.CreateTopic("jeux"); gt.ListTopics(); Chatroom cr = gt.JoinTopic("jeux"); cr.Join(bob); cr.Post("Je suis seul ou quoi ?", bob); cr.Join(joe); cr.Post("Tiens, salut Joe !", bob); cr.Post("Toi aussi tu chat sur les forums de jeux pendant les TP,Bob ? ", joe); AuthentificationManager am = new Authentification(); // users management try { am.AddUser("bob", "123"); Console.WriteLine("Bob has been added !"); am.RemoveUser("bob"); Console.WriteLine("Bob has been removed !"); am.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 { am.AddUser("bob", "123"); Console.WriteLine("Bob has been added !"); am.Authentify("bob", "123"); Console.WriteLine("Authentification OK !"); am.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 { am.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 (IOException e) { Console.WriteLine(e); } Console.ReadLine(); }
public void startServer() { TcpListener l = new TcpListener(new IPAddress(new byte[] { 127, 0, 0, 1 }), port); l.Start(); TopicsManager gt = new TextGestTopics(); List <ChatRoom> ChatRoomsList = new List <ChatRoom>(); while (true) // Exchanges with the clients { try { TcpClient comm = l.AcceptTcpClient(); // Connection with client Console.WriteLine("Connection established @" + comm); Console.WriteLine("Computing operation"); string response; Message mes = new Message(gt.listTopics()); do // Send : Join or Create a Chatroom { // Send : Names of opened chatrooms MessageConnection.sendMessage(comm.GetStream(), new Message("server", "1 Join a chatroom \n2 Create a chatroom")); MessageConnection.sendMessage(comm.GetStream(), mes); mes = MessageConnection.getMessage(comm.GetStream()); response = mes.msg; } while (!response.Equals("1") && !response.Equals("2")); Chatter chatter = new TextChatter(mes.name); // New user of a chatroom chatterList.Add(chatter); TcpClientList.Add(comm); if (response.Equals("1")) // Join an existing chatroom { do { MessageConnection.sendMessage(comm.GetStream(), new Message("serveur", "Please, choose a chatroom: ")); mes = MessageConnection.getMessage(comm.GetStream()); if ((!(gt.IsInside(mes.msg)))) { Console.WriteLine("This chatroom does not exist."); } } while (mes.msg.Length == 0 || (!(gt.IsInside(mes.msg)))); } else // Create a chatroom { do { MessageConnection.sendMessage(comm.GetStream(), new Message("serveur", "Please, give a name to your topic: ")); mes = MessageConnection.getMessage(comm.GetStream()); } while (mes.msg.Length == 0 || gt.IsInside(mes.msg)); gt.createTopic(mes.msg); ChatRoomsList.Add(gt.joinTopic(mes.msg)); } foreach (ChatRoom cr in ChatRoomsList) { if (mes.msg.Equals(cr.getTopic())) { cr.join(chatter); // Add the chatter in the chatroom new Thread(new Receiver(comm, cr).run).Start(); // Create Threads to listen and send messages TcpClient commGet = l.AcceptTcpClient(); chatterList.Add(chatter); TcpClientList.Add(commGet); new Thread(new Receiver(commGet, cr).run).Start(); Message join = new Message("server", "Welcome to " + mes.name + " in the " + mes.msg + " chatroom"); broadcast(join, cr);//send welcome message } } } catch (Exception e) { Console.WriteLine(e.Message); } } }
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); }