用华为mate30(型号;LIO-AN00,Android版本10,EMUI版本11.0.0)真机调试UDP功能,结果无法创建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);时,报错,如下图所示: