예제 #1
0
        private void sendUserObject(BllClient userSending)
        {
            NetworkStream netStream = clt.GetStream();

            byte[] data = userSending.GetBytes();
            int    size = userSending.size;

            byte[] packsize = new byte[2];
            packsize = BitConverter.GetBytes(size);
            netStream.Write(packsize, 0, 2);
            netStream.Write(data, 0, size);
            netStream.Flush();
        }
예제 #2
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);
     }
 }
예제 #3
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();
     }
 }