public ClientHandlerFactory(ClientHandler.messageReceivedCallback mrc)
 {
     this.mrc = mrc;
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int port = 9000;
            if (args.Length > 1)
            {
                if (args[0].Equals("-p"))
                {
                    Int32.TryParse(args[1], out port);
                }
            }

            users = new List<User>();
            ServerActions.clientAcceptedCallback cac = new ServerActions.clientAcceptedCallback(clientAccepted);
            ServerActions.clientDisconnectedCallback cdc = new ServerActions.clientDisconnectedCallback(clientDisconnected);
            ServerActions sa = new ServerActions();
            sa.setClientAcceptedCallback(cac);
            sa.setClientDisconnectedCallback(cdc);

            ClientHandler.messageReceivedCallback mrc = new ClientHandler.messageReceivedCallback(handleMessage);
            ClientHandlerFactory chf = new ClientHandlerFactory(mrc);

            using (s = new Server.Server(port, chf, sa))
            {
                string cmd = "";
                while (!(cmd = Console.ReadLine()).Equals("exit", StringComparison.CurrentCultureIgnoreCase))
                {
                    if ("start".Equals(cmd, StringComparison.CurrentCultureIgnoreCase))
                    {
                        s.start();
                    }
                    else if ("stop".Equals(cmd, StringComparison.CurrentCultureIgnoreCase))
                    {
                        s.stop();
                    }
                }
            }
        }