HarmonyOS 使用udp send方法发送消息时提示Bad file descriptor?

主流程代码如下:

import { socket } from '@kit.NetworkKit'

const udp = socket.constructUDPSocketInstance() as socket.UDPSocket
const netAddress: socket.NetAddress = { address: '255.255.255.255', family: 1 }
let decodedMessage: string
const message = 'WloBEUgAkgCoAAAAFSklEQkHGBQAAAAAAAAAAAAAAAAAAAAAAAAAAH91vWs+T4t2LoScbleNZZAFN0CBc5DaiUZmYBtoGu69'
decodedMessage = buffer.from(message, 'base64').toString()
const sendOptions: socket.UDPSendOptions = {
  data: decodedMessage as string | ArrayBuffer,
  address: netAddress
}
udp.send(sendOptions, (err: BusinessError) => {
  if (err) {
    console.log('sendUDPMessage err')
    return
  }
  console.log('sendUDPMessage success')
})

每次发送消息后,err处都返回Bad file descriptor,请问这个错误有没有具体的排查思路?

阅读 505
1 个回答
logo
HarmonyOS
子站问答
访问
宣传栏