Esempio n. 1
0
        private void ClientForm_ButtonSendClicked(string data, bool e)
        {
            if (data.Contains(ChatConstants.Separator))
            {
                MessageBox.Show("Your message has invalid symbols!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ChatLogic.SendMessage(data);
        }
Esempio n. 2
0
 // Установка соединения
 private void ConnectTcpClient()
 {
     if (_isConnected == false)
     {
         _tcpClient = new TcpClient();
         _tcpClient.Connect(_ip, _port);
         ChatLogic.SetTcpClient(_tcpClient);
         _isConnected = true;
         _clientForm.SetIsConnected(_isConnected);
     }
 }
Esempio n. 3
0
 // Разрыв соединения
 private void DisconnectTcpClient(bool disposing = false)
 {
     if (_isConnected)
     {
         _tcpClient.GetStream().Close();
         _tcpClient.Close();
         ChatLogic.SetTcpClient(null);
         _isConnected = false;
         if (disposing == false)
         {
             _clientForm.SetIsConnected(_isConnected);
         }
     }
 }
Esempio n. 4
0
        // Асинхронное обслуживание подключения
        private void ConnectionServiceAsync()
        {
            Task.Run(() =>
            {
                ChatLogic.SetUsername();
                _clientForm.ClearMessages();

                var data = ChatLogic.GetOnlineUsers();
                if (string.IsNullOrEmpty(data) == false)
                {
                    SetOnlineUsers(data);
                }

                data = ChatLogic.GetChatCommands();
                if (string.IsNullOrEmpty(data) == false)
                {
                    SetChatCommands(data);
                }

                ChatLogic.ReceiveMessages();
                DisconnectTcpClient();
            });
        }
Esempio n. 5
0
 private void ClientForm_ChatCommandClicked(string data, bool e)
 {
     ChatLogic.SendMessage(data);
 }