按钮触发这段代码
UDPSocket.send() 报错 onError: send: fail sendUDPSocketMessage:fail function cannot run on service
同时UDPSocket.bind()没有返回port
const udpClient = wx.createUDPSocket();
const udpPort = udpClient.bind();
console.log("udp client port: " + udpPort); // 这里输出是: undefined
udpClient.onListening((res) => {
console.log("onListening: ")
console.log(res)
});
udpClient.send({
address: '255.255.255.255',
port: 8266,
message: data
});
udpClient.onError((err) => {
console.log("onError: ")
console.log(err) // send: fail sendUDPSocketMessage:fail function cannot run on service
});
udpClient.onMessage((res) => {
console.log("onMessage: ")
console.log(res)
udpClient.close()
});
你好,检查下是否是基础库的版本太低了。
安卓调用的话 onError: send: fail sendUDPSocketMessage:fail:not supported
UDPSocket.bind()也没有返回port
const udp = wx.createUDPSocket()
udp.bind()
udp.send({
address: '255.255.255.255',
port: 8266,
message: 'hello, how are you'
})
udp.onError((err) => {
console.log(err) // 我把文档上的示例代码拷贝下来 还是老问题
})