|
(为了高效,请按如下格式提问)
硬件主板型号:SCDAYU200鸿蒙开发板
固件名称/系统版本:OpenHarmony4.0.11
自编的或固件下载地址:官网下载
Log日志: (可以导出,用TXT附件上传)
问题描述及复现步骤:
dayu200的开发版,购买的设备开发版系统是OpenHarmony3.x版本,调试UDP通讯,出现{"code":2301013,"message":"Permission denied"}问题,参考这个帖子,https://developer.huawei.com/con ... 0201139780808812402,固件刷到了4.0版本,Dayu200上运行依然是2301013报错;
成功案例:在模拟器上通讯可以实现发送和接收,在华为mate30上实现UDP通讯,可以实现发送和接收
失败案例:dayu200,OpenHarmony3.x设备,OpenHarmony4.0设备,Socket.bind均出现绑定失败的问题
//执行UDP通讯的对象
udpSocket = socket.constructUDPSocketInstance();
//发送消息到目的ip和端口
udpSend(sendMsg:string|ArrayBuffer) {
//目的ip和端口
let remoteAddress = { address: AppInfo.UDP_Server_IP, port: AppInfo.UDP_Server_Port, family: 1 }
this.udpSocket.send({ data: sendMsg, address: remoteAddress })
.then(async () => {
})
.catch((e) => {
console.log('发送失败' + JSON.stringify(e))
})
}
//绑定本地端口
async udpReceive() {
//本地地址
let localAddress = { address: "0.0.0.0", port: AppInfo.UDP_Receive_Port, family: 1 }
//绑定服务
await this.udpSocket.bind(localAddress)
.then(() => {
console.log('bind success')
})
.catch((e) => {
console.log('bind fail ' + JSON.stringify(e))
})
//收到消息时的处理
this.udpSocket.on("message", async (value) => {
let msg = this.buf2String(value.message)
let remoteIP = value.remoteInfo.address
let remotePort = value.remoteInfo.port.toString()
//对端ip地址和端口的字符串形式
let remoteAddr = "[" + remoteIP + ":" + remotePort + "]:"
let time = await this.getCurrentTimeString()
console.log("【接收】" + remoteAddr + msg + time)
})
console.log("【UDP服务】开启UDP接收")
}
|
|