コード例 #1
0
 // gửi gói tin
 public void Send(string ms)
 {
     try
     {
         // gửi dữ liệu ở dạng nhị phân (byte)
         myUser.setMessage(ms);
         NetworkStream netStream = clt.GetStream();
         byte[]        data      = myUser.GetBytes();
         int           size      = myUser.size;
         byte[]        packsize  = new byte[2];
         // convert byte -> string
         packsize = BitConverter.GetBytes(size);
         netStream.Write(packsize, 0, 2);
         netStream.Write(data, 0, size);
         netStream.Flush();
     }
     catch
     {
         MessageBox.Show("Lỗi kết nối", "Lỗi!",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
         Application.Exit();
     }
 }
コード例 #2
0
        private void loginBtn_Click(object sender, EventArgs e)
        {
            string name = usNameTxt.Text;
            string pass = passTxt.Text;

            if (name != "" && pass != "")
            {
                BllClient userSending = new BllClient(name, pass);
                userSending.setMessage("dang_nhap-" + keyDangNhap);
                myUser            = userSending;
                myUser.receiveDir = 1;
                sendUserObject(userSending);
            }
            else
            {
                MessageBox.Show("User name or Password are error", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
 public void sendMessage(string ms)
 {
     try
     {
         myUser.setMessage(ms);
         NetworkStream netStream = clt.GetStream();
         byte[]        data      = myUser.GetBytes();
         int           size      = myUser.size;
         byte[]        packsize  = new byte[2];
         packsize = BitConverter.GetBytes(size);
         netStream.Write(packsize, 0, 2);
         netStream.Write(data, 0, size);
         netStream.Flush();
     }
     catch
     {
         MessageBox.Show("Error login", "Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }