查看: 452|回复: 1

DAYU200,UDP通讯,code:2301013

[复制链接]

1

主题

1

回帖

211

积分

中级会员

Rank: 3Rank: 3

积分
211
发表于 2024-7-18 15:27:26 | 显示全部楼层 |阅读模式
(为了高效,请按如下格式提问)

硬件主板型号: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接收")
}


回复

使用道具 举报

1

主题

1

回帖

211

积分

中级会员

Rank: 3Rank: 3

积分
211
 楼主| 发表于 2024-7-26 17:29:45 | 显示全部楼层
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|风火轮WIKI|手机版|小黑屋|深圳风火轮团队 ( 粤ICP备17095099号 )

GMT+8, 2024-9-8 08:14 , Processed in 0.048143 second(s), 19 queries .

快速回复 返回顶部 返回列表
 
【客服1】 商务合作 15289193
【客服2】 业务洽谈 13257599
【客服3】 售前咨询 510313198
【邮箱】
smartfire@smartfire.cn