Ejemplo n.º 1
0
        private void ButtonSend_Click(object sender, EventArgs e)
        {
            if (!netManager.IsOpen())
            {
                MessageBox.Show("Please click 'open' button first !");
                return;
            }

            string send_str = textBoxNetSend.Text;

            if (send_str == String.Empty)
            {
                MessageBox.Show("Please input sending string !");
                return;
            }

            if (checkBoxNetSendHex.Checked)
            {
                byte[] data = HexFormatUtils.String2HexByte(send_str);
                if (data != null)
                {
                    netManager.Send(data);
                }
                else
                {
                    MessageBox.Show("Please input just hex strings. e.g. 1A ff 06");
                }
            }
            else
            {
                Encoding encodingGB2312 = Encoding.GetEncoding("gb2312");
                Byte[]   byte_array     = encodingGB2312.GetBytes(send_str.ToCharArray()); //Encoding.Default.GetBytes(send_str.ToCharArray());
                netManager.Send(byte_array);
            }
        }
Ejemplo n.º 2
0
 private void OnNetRecvListener(byte[] data, int length, IPEndPoint iped)
 {
     if (checkBoxNetRecvHex.Checked)
     {
         BeginInvoke(new MethodInvoker(delegate
         {
             AddRecvMsg(HexFormatUtils.HexByte2String(data));
         }));
     }
     else
     {
         BeginInvoke(new MethodInvoker(delegate
         {
             Encoding encodingGB2312 = Encoding.GetEncoding("gb2312");
             Char[] c_data           = encodingGB2312.GetChars(data); //Encoding.ASCII.GetChars(data);
             string str = new String(c_data);
             AddRecvMsg(str);
         }));
     }
 }