Exemple #1
0
        private void ServeClient(object obj)
        {
            Weitrest      weitrest = (Weitrest)obj;
            User          user     = weitrest.User;
            NetworkStream stream   = weitrest.Client.GetStream();
            TcpClient     client   = weitrest.Client;

            if (user != null)
            {
                SendMessage(user.Role, stream);
                if (user.Role == "Управляющий")
                {
                    SendReports(stream);
                    AddToConnectedUsers(user);
                    RecieveMessage(stream, client, user, false);
                }
                else
                {
                    AddToConnectedUsers(user);
                    RecieveMessage(stream, client, user, true);
                }
            }
            else
            {
                SendMessage("Неверное имя пользователя или пароль", stream);
                this.Invoke(new MethodInvoker(() =>
                {
                    textBoxLog.Text += "\n" + DateTime.Now.ToShortTimeString() + ": Ошибка аутентификации пользователя";
                }));
            }
        }
Exemple #2
0
        private void Listen()
        {
            while (true)
            {
                try
                {
                    TcpClient     client = server.AcceptTcpClient();
                    NetworkStream stream = client.GetStream();

                    string userInfo = GetMessage(stream);
                    User   user     = GetUser(userInfo);

                    Weitrest weitrest = new Weitrest(client, user);

                    Thread thread = new Thread(new ParameterizedThreadStart(ServeClient));
                    thread.Start(weitrest);
                }
                catch (Exception)
                {
                    this.Invoke(new MethodInvoker(() =>
                    {
                        textBoxLog.Text += "\n" + DateTime.Now.ToShortTimeString() + ": ошибка подключения!!!";
                    }));
                }
            }
        }