Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();
            AddDoubleClickEventStyle(lbUsers, dGSerials_MouseDoubleClick);
            ResourceDictionary myResourceDictionary = new ResourceDictionary();

            myResourceDictionary.Source = new Uri("Styles.xaml", UriKind.Relative);
            Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);

            try
            {
                LogIn dialog = new LogIn();
                if (dialog.ShowDialog() == true)
                {
                    client = new ChatClient(dialog.username.Text, "127.0.0.1", 11000, this);
                    client.Connect();

                    AddLobbyTab();
                    lbUsers.ItemsSource    = client.users;
                    client.PrivateMessage += PrivateMessageHandler;
                    client.ReciveMessageAsync();
                }
                else
                {
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.Close();
            }

            CommandBinding binding = new CommandBinding(Commands.SendMessageCommand);

            binding.CanExecute += binding_CanExecute;
            binding.Executed   += binding_Executed;
            this.CommandBindings.Add(binding);
            btnSend.Command = Commands.SendMessageCommand;
        }
Ejemplo n.º 2
0
        static void Main()
        {
            Console.WriteLine("Application start...[ThreadID:{0}]", Thread.CurrentThread.ManagedThreadId);

            string app_identifier = "chat";
            string server_ip      = "127.0.0.1";
            int    server_port    = 11515;
            int    max_client     = 100;

            ChatClient client = new ChatClient();

            client.Init(app_identifier);

            ChatServer server = new ChatServer();

            server.Init(app_identifier, server_port, max_client);

            while (true)
            {
                Console.Write("command> ");
                string line = Console.ReadLine();
                if (line == "quit")
                {
                    client.Close();
                    server.Stop();
                    break;
                }
                else if (line == "start server")
                {
                    server.Start();
                }
                else if (line == "connect")
                {
                    client.Connect(server_ip, server_port);
                }
                else if (line.IndexOf("login") >= 0)
                {
                    string[] token = line.Split(' ');
                    if (token.Length >= 2)
                    {
                        client.Login(token[1]);
                    }
                    else
                    {
                        Console.WriteLine("Invalid command.");
                    }
                }
                else if (line.IndexOf("logout") >= 0)
                {
                    client.Logout();
                }
                else if (line.IndexOf("send") >= 0)
                {
                    string[] token = line.Split(' ');
                    if (token.Length == 3)
                    {
                        client.Send(token[1], token[2]);
                    }
                    else
                    {
                        Console.WriteLine("Invalid command.");
                    }
                }
                else
                {
                    if (line.Length > 0 && client.IsLogin())
                    {
                        client.SendToAll(line);
                    }
                }
            }

            Console.WriteLine("Application is quitted!");
            Console.Read();
        }
Ejemplo n.º 3
0
        static void Main()
        {
            Console.WriteLine("Application start...[ThreadID:{0}]", Thread.CurrentThread.ManagedThreadId);

            string app_identifier = "chat";
            string server_ip = "127.0.0.1";
            int server_port = 11515;
            int max_client = 100;

            ChatClient client = new ChatClient();
            client.Init(app_identifier);

            ChatServer server = new ChatServer();
            server.Init(app_identifier, server_port, max_client);
            
            while (true)
            {
                Console.Write("command> ");
                string line = Console.ReadLine();
                if (line == "quit")
                {
                    client.Close();
                    server.Stop();
                    break;
                }
                else if (line == "start server")
                {
                    server.Start();
                }
                else if (line == "connect")
                {
                    client.Connect(server_ip, server_port);
                }
                else if (line.IndexOf("login") >= 0)
                {
                    string[] token = line.Split(' ');
                    if (token.Length >= 2)
                    {
                        client.Login(token[1]);
                    }
                    else
                    {
                        Console.WriteLine("Invalid command.");
                    }
                }
                else if (line.IndexOf("logout") >= 0)
                {
                    client.Logout();
                }
                else if (line.IndexOf("send") >= 0)
                {
                    string[] token = line.Split(' ');
                    if (token.Length == 3)
                    {
                        client.Send(token[1], token[2]);
                    }
                    else
                    {
                        Console.WriteLine("Invalid command.");
                    }
                }
                else
                {
                    if (line.Length > 0 && client.IsLogin())
                    {
                        client.SendToAll(line);
                    }
                }
            }

            Console.WriteLine("Application is quitted!");
            Console.Read();
        }