//具体代码片段如下:出现现象编译器上都是正常OK 真机调试如上图所示 //app.js const TCPSocket = wx.createTCPSocket(); TCPSocket.onMessage((res) => { console.log(res) var pages = getCurrentPages() var index = pages[pages.length - 1] index.setData({ motto: res.remoteInfo.address }) }) function TCPSend(cmd, data, len) { let buffer = new ArrayBuffer(6 + len); let dataArray = new Int8Array(buffer); dataArray[0] = 0x33; dataArray[1] = 0x7c; dataArray[2] = cmd; dataArray[3] = len >> 8; dataArray[4] = len; if (data) { for (let i = 0; i < len; i++) { dataArray[5 + i] = data[i]; } dataArray[5 + len] = 0x42; } else { dataArray[5] = 0x42; } TCPSocket.write(dataArray) } TCPSocket.onError((res) => { console.log("错误:", res) TCPSocket.close() }) module.exports = { TCPSend, TCPSocket } //index.js //按钮点击发送连接申请 bind2(){ appC.TCPSocket.connect({ address: "at.efl-tech.com", //8.130.28.255 port: 44514 }) appC.TCPSocket.onConnect(() => { console.log("连接上来了") appC.TCPSend(0x02, null, 0) setTimeout(function () { let data = new Uint8Array(); data = [0, 0, 0, 111, 49, 50, 51, 52, 53, 54] appC.TCPSend(0x05, data, 10) }, 100) }) }, //按钮发送测试 bind5() { let data = new Uint8Array(); data = [0, 0, 0, 111, 49, 50, 51, 52, 53, 54] appC.TCPSend(0x05, data, 10) }, //按钮发送测试1 bind11() { appC.TCPSend(0x11, null, 0) }, //按钮发送测试2 bind50() { appC.TCPSend(0x50, null, 0) },
TCPSocket 模拟器正常 真机调试报错?[图片] [图片] 发送第一条第二条信息成功,但是adress:0.0.0.0 port:0 然后报错 errCode为-2 查看文档对应errno又表示正常 白名单已配置
2023-08-29