TCPSocket发送数据问题?
通过tcpsocket 给标签打印机发送指令,打印机没有响应。 beep(){ const tcp = wx.createTCPSocket(); tcp.onError((res)=>{ console.log(res); }); tcp.onMessage((res)=>{ console.log(res); }) tcp.connect({address: '192.168.0.200', port: 9100}); tcp.write('BEEP\n'); tcp.close(); } 用c#编写代码测试,发现没有问题: class Program { static void Main(string[] args) { var client = new TcpClient(); client.Connect("192.168.0.200", 9100); var s = client.GetStream(); var buffer = Encoding.ASCII.GetBytes("BEEP\n"); s.Write(buffer, 0, buffer.Length); s.Close(); Console.WriteLine("Done!!!"); } } 这是我用网络抓包工具抓的数据包: 00 00 00 00 00 00 00 57 65 BB 08 05 00 D9 01 08 01 00 80 BC 13 A8 C3 D7 55 50 2B 73 D4 0B 75 00 47 50 6D 49 CD 00 00 AA AA 03 00 00 00 08 00 45 00 00 2D C0 DC 40 00 80 06 B7 B2 C0 A8 00 23 C0 A8 00 C8 F5 7F 23 8C 1E 45 B2 87 00 00 19 96 50 18 FA F0 9D 96 00 00 42 45 45 50 0A .......We»...Ù....¼.¨Ã×UP+sÔ.u.GPmIÍ..ªª......E..-ÀÜ@..·²À¨.#À¨.Èõ#.E²...P.úð..BEEP. c#发送的数据包中明显有个BEEP,但是小程序发送的数据包中没法发现BEEP,我推测是网络字节顺序和本地字节顺序问题,不知如何解决。