组件名称:UDPSocket 微信版本号:8.0.1 基础库版本号:2.16.0
在真机调试时无法创建udp对象,代码如下:
scanDivice: function () {
const udp = wx.createUDPSocket();
const port = udp.bind(12476);
var inter = setInterval(function () {
udp.send({
address: '255.255.255.255',
port: 12467,
message: '{"action":"scanDevice"}'
});
console.log("end send")
}.bind(this), 1000);
udp.onMessage(function (res) {
let unit8Arr = new Uint8Array(res.message);
let encodedString = String.fromCharCode.apply(null, unit8Arr);
let message = decodeURIComponent(escape((encodedString)));
console.log('udp_msg::' + message + ' ip:' + res.remoteInfo.address);
if (inter) {
clearInterval(inter);
udp.close();
}
});
},
当执行到const port = udp.bind(12476);语句时,报Cannot read property 'bind' of undefined错误,如下图: