C#通过TCP发送十六进制

时间:2018-12-17 10:43:43

标签: c# tcp hex

我正在尝试通过TCP发送十六进制数据。

我知道如何在UDP中执行此操作,但TCP不适用于我:

TcpClient client = new TcpClient("192.168.1.202", 8000);
NetworkStream stream = client.GetStream();

ASCIIEncoding Enc = new ASCIIEncoding();
Byte[] s = new byte[] { 0xa5, 0x5b, 0x02, 0x03, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07 };
Console.WriteLine(s.ToString());

1 个答案:

答案 0 :(得分:0)

我已经这样解决了:

TcpClient client = new TcpClient("192.168.1.202", 8000);

        Byte[] s = new byte[] { 0xa5, 0x5b, 0x02, 0x03, 0x01, 0x00, 0x01, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0xf9 };
        NetworkStream stream = client.GetStream();
        stream.Write(s, 0, s.Length);