Page({
handleTcp() {
const tcp = wx.createTCPSocket()
tcp.connect({
address: '10.81.140.93',
port: 41668
})
tcp.onConnect(() => {
console.log("onConnect")
})
tcp.onMessage((message, remoteInfo, localInfo) => {
console.log("message.message")
let data = new Uint8Array(message.message)
let buf = ''; //结果保存在这里
for (let i = 0; i < data.byteLength; i++) {
buf += String.fromCodePoint(data[i]);//合成保存到变量,
}
console.log(buf);//打印一下
if (buf == 'jlz') { //测试效果
console.log('通过测试');
}
console.log(message)
console.log(remoteInfo)
console.log(localInfo)
})
tcp.onError((res) => {
console.log(res)
})
setTimeout(function () {
// 3s后,关闭socket
tcp.close(() => {
console.log("close")
})
}, 3000)
}
})
你好,看接口报错是什么,看onerror返回什么