public void InitializeConnection(string serverIP, string username, string userpassword) { tcpClient = new TcpClient(); IPAddress ipAddr = IPAddress.Parse(serverIP); try { tcpClient.Connect(ipAddr, 1986); } catch { clientUpdatedCallback?.Invoke("Server is not accessable!"); return; } UserName = username; UserPassword = userpassword; ServerIP = serverIP; // Запускаем поток для получения сообщений и дальнейшего общения // thrMessaging = new Thread(new ThreadStart(ReceiveMessages)); thrMessaging = new Thread(ChatClientInteraction); thrMessaging.Start(); mConnected = true; clientConnectedCallback?.Invoke(); }
private void AddMessageToListBox() { while (Connected) { lock (sync) { if (Connected == false) { break; } // Show the messages in the log TextBox string message = srReceiver.ReadLine(); mess = mess.Deserialize(message); AddUser(mess.UserName, mess.SmileName); UpdateLogCallback.Invoke(mess.CurrentMessage); } } }