public Chatroom JoinTopic(string topic) { Message message = new Message(Header.JOIN_TOPIC, topic); try { SendMessage(message); Message answer = GetMessage(); int port; Int32.TryParse(answer.data[0], out port); ClientChatRoom chatroom = new ClientChatRoom(); chatroom.SetServer(Adr, port); chatroom.Connect(); return(chatroom); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } }
public IChatroom joinTopic(string topic) { Message request = new Message(new Header("Client", MessageType.JOIN_TOPIC), topic); sendMessage(request); Message reply = getMessage(); int port = int.Parse(reply.data); ClientChatRoom ccr = new ClientChatRoom(Ip,port,topic); ccr.connect(); return ccr; }
public IChatroom joinTopic(string topic) { Message request = new Message(new Header("Client", MessageType.JOIN_TOPIC), topic); sendMessage(request); Message reply = getMessage(); int port = int.Parse(reply.data); ClientChatRoom ccr = new ClientChatRoom(Ip, port, topic); ccr.connect(); return(ccr); }
static void Main(string[] args) { ClientTopicsManager ctm = new ClientTopicsManager(); ctm.SetServer("127.0.0.1", 26763); ctm.Connect(); Console.WriteLine("Create user, Connect with a name and password"); string name = Console.ReadLine(); string password = Console.ReadLine(); string error = ""; if (ctm.Login(name, password, ref error)) { List <string> topics = ctm.ListTopics(); if (!topics.Contains("Jeux Vidéo")) { ctm.CreateTopic("Jeux Vidéo"); } ClientChatRoom clientChatRoom = (ClientChatRoom)ctm.JoinTopic("Jeux Vidéo"); TextChatter c = new TextChatter(name); clientChatRoom.Join(c); string quit = "no"; while (quit == "no") { string msg = Console.ReadLine(); if (msg == "yes") { quit = msg; } clientChatRoom.Post(msg, c); } clientChatRoom.Disconnect(); ctm.Disconnect(); } Console.Read(); }
public IChatRoom joinTopic(string topic) { //Send the request for a socket for the client to join to the topic Message msg = new Message(new Header("Someone", "JOIN_TOPIC"), topic); sendMessage(msg); //Get a free port in reply Message replyMsg = getMessage(); int port = 0; if (replyMsg != null) { port = int.Parse(replyMsg.data); ClientChatRoom chatRoom = new ClientChatRoom(ip, port, topic); chatRoom.setServer(ip, port); chatRoom.connect(); return(chatRoom); } //Connect the client to the desired topic with the port return(null); }