public ChatterConsole(ClientTalker cli) { InitializeComponent(); this.messageBox.KeyDown += new KeyEventHandler(messageBox_KeyDown); this.FormClosing += new FormClosingEventHandler(ChatterConsole_FormClosing); this.clientTalker = cli; this.messageBox.BringToFront(); this.AutoScroll = true; this.chatBoard.SelectionAlignment = HorizontalAlignment.Left; this.chatBoard.Dock = DockStyle.Fill; this.chatBoard.ScrollBars = RichTextBoxScrollBars.ForcedBoth; this.messageBox.Focus(); this.Focus(); }
static void Main(string[] args) { if (!IsInputValid(args)) { return; } Logger.Logger.InitializeLogger(null); TcpClient tcp = new TcpClient(); Console.Write("Enter username: "******"Enter password: "******"You are being authenticate with the server. Please wait..."); try { tcp.Connect(new IPEndPoint(ipaddress, portNumber)); } catch (Exception e) { Logger.Logger.WriteException(e); Console.WriteLine("Are you sure server address specified is right?"); Console.WriteLine(); Console.WriteLine("It cannot be reached. Check the connectivity to the server."); return; } try { ClientTalker client = new ClientTalker(tcp); client.Authenticate(userName, password); if (!client.IsServerActive) { Console.WriteLine("Problem while trying to communicate with the server"); Console.WriteLine("Check the internet connection and if the server is up or not"); return; } while (!client.IsAuthenticated && client.IsServerActive) { Console.WriteLine("Either user name or password are wrong. Please try again"); Console.Write("Enter username: "******"Enter password: "******"You are being authenticate with the server. Please wait..."); try { client.Authenticate(userName, password); } catch (Exception) { if (!client.IsAuthenticated) { Console.WriteLine("Unable to authenticate the provided user with the server"); Console.WriteLine("Check your credentials and try again"); Console.WriteLine("Press return to exit......"); Console.ReadLine(); return; } } } if (!client.IsAuthenticated) { Console.WriteLine("Unable to authenticate the provided user with the server"); Console.WriteLine("Check your credentials and try again"); } bool hasChatted = false; while (client.IsAuthenticated) { ChatterConsole chatConsole = new ChatterConsole(client); client.SetConsole(chatConsole); hasChatted = true; Application.Run(chatConsole); //string chatMessage = Console.ReadLine(); //client.SendMessage(chatMessage); } if (!client.IsServerActive && !hasChatted) { Logger.Logger.WriteError("Problem occured when trying to communicate with the server"); Logger.Logger.WriteError("Server closed the session"); Console.WriteLine("Press return to exit......"); Console.ReadLine(); } //Console.WriteLine("Press any key to exit........"); //Console.ReadLine(); } catch (Exception e) { Console.WriteLine("Some error occured"); Console.WriteLine("Error message:" + e.Message); Console.WriteLine("Stack trace:" + e.StackTrace); Console.WriteLine("Try again after checking the Internet connectivity"); Console.WriteLine("Make sure that you have sufficent permission to open a port on the system"); Console.WriteLine("Support contact: Machiry Aravind Kumar"); Console.WriteLine("Press return to exit......"); Console.ReadLine(); } }