private void Connect() { try { this.Hide(); Login frmLogin = new Login(); frmLogin.ShowDialog(this); ip = frmLogin.IP(); // The TcpClient is a subclass of Socket, providing higher level // functionality like streaming. client = new TcpClient(ip, PORT_NUM); // Start an asynchronous read invoking DoRead to avoid lagging the user // interface. // Bắt đầu luồng Receive để tránh tình trạng lag giao diện người dùng client.GetStream().BeginRead(readBuffer, 0, READ_BUFFER_SIZE, new AsyncCallback(Receive), null); // Make sure the window is showing before popping up connection dialog. //Gửi tên tài khoản đăng nhập và mật khẩu đến server để kiểm tra xem có hợp lệ SendData("CONNECT|" + frmLogin.textBox1.Text + "|" + frmLogin.textBox3.Text); user = frmLogin.textBox1.Text; labelName.Text = " : " + user; frmLogin.Dispose(); this.Show(); } catch (Exception Ex) { MessageBox.Show("Không thể kết nối với máy chủ. Vui lòng thực hiện lại việc đăng nhập.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Dispose(); } }