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); }
// Установка соединения private void ConnectTcpClient() { if (_isConnected == false) { _tcpClient = new TcpClient(); _tcpClient.Connect(_ip, _port); ChatLogic.SetTcpClient(_tcpClient); _isConnected = true; _clientForm.SetIsConnected(_isConnected); } }
// Разрыв соединения private void DisconnectTcpClient(bool disposing = false) { if (_isConnected) { _tcpClient.GetStream().Close(); _tcpClient.Close(); ChatLogic.SetTcpClient(null); _isConnected = false; if (disposing == false) { _clientForm.SetIsConnected(_isConnected); } } }
// Асинхронное обслуживание подключения 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(); }); }
private void ClientForm_ChatCommandClicked(string data, bool e) { ChatLogic.SendMessage(data); }