private static bool ConnectToServer() { var clientManager = new ClientManager(); Console.Write("IP Address: "); if (!clientManager.SetServerIpAddress(Console.ReadLine())) { return(false); } Console.Write("Port: "); if (!ushort.TryParse(Console.ReadLine(), out var port)) { Console.WriteLine("Port number is incorrect."); return(false); } clientManager.Port = port; try { clientManager.ConnectToServer().Wait(1000); } catch (Exception) { return(false); } clientManager.MessageReceived += OnMessageReceived; do { var input = Console.ReadLine(); if (string.Equals("exit", input, StringComparison.OrdinalIgnoreCase)) { clientManager.CloseAndDisconnect(); break; } clientManager.SendToServer(input).Wait(1000); } while (true); clientManager.DisconnectFromServer(); return(true); }
private void LoginToServer() { if (txtUserName.Text.Trim() == "") { frmPopup popup = new frmPopup(PopupSkins.SmallInfoSkin); popup.ShowPopup("Error", "Username is empty !", 1000, 2000, 2000); SetEnablity(true); } else if (txtPassword.Text.Trim() == "") { frmPopup popup = new frmPopup(PopupSkins.SmallInfoSkin); popup.ShowPopup("Error", "Password is empty !", 1000, 2000, 2000); SetEnablity(true); } else { _client.UserName = txtUserName.Text.Trim(); _client.Password = txtPassword.Text.Trim(); _client.ConnectToServer(); } }