Пример #1
0
        /// <summary>
        /// Setup the connection and server specific information for this user.
        /// </summary>
        /// <param name="username"></param>
        /// <returns>The ChatServer instance to play with</returns>
        ///
        public static RemoteChatServer SetupUserAndConnection(String username)
        {
            String uri = "tcp://localhost:4010";

            MyChatClientImpl client = new MyChatClientImpl(username);
            RemoteChatServer server = ChatHelper.NewServer(uri, null, client);

            server._StartAndWaitUp(4000);

            return(server);
        }
Пример #2
0
 /// <summary>
 /// Constructs the ChatClientImpl
 /// </summary>
 /// <param name="whoami"></param>
 /// <param name="snub"></param>
 public ImplChatClient(RemoteChatServer server, String whoami, bool snub)
 {
     this.server = server;
     _whoami     = whoami;
     _snub       = snub;
 }
Пример #3
0
        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();
        }
Пример #4
0
 public ChatClient NewChatClient(RemoteChatServer server)
 {
     return(client);
 }
Пример #5
0
 public void TestLogin()
 {
     fred_server = SetupUserAndConnection("badUser");
     fred_server.login("badUser", "badPass");
 }
Пример #6
0
 public void TestLogin3()
 {
     fred_server = SetupUserAndConnection(null);
     fred_server.login(null, null);
 }
Пример #7
0
 public void TestLogin2()
 {
     fred_server = SetupUserAndConnection(_fred);
     fred_server.login(_fred, _fred);
     fred_server.login(_fred, _fred);
 }
Пример #8
0
 public void AssignNullToConnections()
 {
     fred_server = null;
 }
Пример #9
0
 public ChatClient NewChatClient(RemoteChatServer server)
 {
     return(new ImplChatClient(server, user, false));
 }