private static void Do_who(MainChatClient client) { String[] names = client.GetWhoIsOnline(); foreach (String name in names) { Console.WriteLine(" " + name); } }
public static void Main(String[] args) { string uri; if (args.Length == 1) { uri = args[0]; } else if (args.Length == 0) { uri = "tcp://localhost:4005?TcpTransport.reconnectDelay=4000"; } else { Console.WriteLine("usage: MainChatClient [<uri>]"); Environment.Exit(1); return; } Console.WriteLine("Connecting to chat server at " + uri); MainChatClient client = new MainChatClient(); RemoteChatServer server = ChatHelper.NewServer(uri, null, new MyChatClientFactory(client)); server._StartAndWaitUp(4000); Console.WriteLine("( connected, enter commands or help)"); while (true) { Console.Write("cmd : "); Console.Out.Flush(); String s = Console.ReadLine(); if (s == null) { break; } if (s.Length == 0) { continue; } char[] seps = { ' ', '\t', '\r', '\n' }; String[] cmds = s.Split(seps); if (cmds.Length == 0) { continue; } if (cmds[0].Equals("help")) { Do_help(); continue; } if (cmds[0].Equals("login")) { Do_login(server, cmds); continue; } if (cmds[0].Equals("logout")) { server.logout(); continue; } if (cmds[0].Equals("quit")) { break; } if (cmds[0].Equals("send")) { // extract message // note: cmds[2] = message to be extracted if (cmds.Length < 3) { Console.WriteLine("usage : send <user> <msg>"); continue; } char[] seps2 = { '\n', '\r' }; String msg = ""; for (int i = 2; i < cmds.Length; i++) { msg = msg + " " + cmds[i]; } String[] cmds2 = msg.Split(seps2); Do_send(server, cmds[1], cmds2); continue; } if (cmds[0].Equals("who")) { Do_who(client); continue; } Console.WriteLine("unknown command"); Do_help(); } //server.logout(); //( ( RemoteChatServer ) server )._StopAndWaitDown( 4000 ); server._Stop(); }
public MyChatClientFactory(MainChatClient client) { this.client = client; }