HarmonyOS UDP socket bind失败?

[socket_exec.cpp 992] bind failed, socket:64, errno:99
阅读 540
1 个回答

socket的bind函数入参地址是本机IP,本机获取IP参考:

let localAddress = resolveIP(wifiManager.getIpInfo().ipAddress);

export function resolveIP(ip: number): string {
  if (ip < 0 || ip > 0xFFFFFFFF) {
    throw ('The number is not normal!');
  }
  return (ip >>> 24) + '.' + (ip >> 16 & 0xFF) + '.' + (ip >> 8 & 0xFF) + '.' + (ip & 0xFF);
}

export function checkIp(ip: string): boolean {
  let ipRegex = /^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/;
  return ipRegex.test(ip);
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
logo
HarmonyOS
子站问答
访问
宣传栏