GCDAsyncUdpSocket immediately closes when sending to an IPv6 address

前端 未结 2 1550
走了就别回头了
走了就别回头了 2021-01-14 11:23

I\'m connecting via UDP to a server on a different device which is advertised by Bonjour. When both the iOS device which this code is running on, and the server, are on our

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-14 12:15

    What I did was call setPreferIPv4 and setIPv6Enabled:FALSE on the socket, which would make connecting fail if the DNS lookup only returned an IPv6 address. Then, in udpSocket:didNotConnect: i checked for that specific error (IPv6 has been disabled and DNS lookup found no IPv4 address(es).) and if the connect failed for that reason, went back into my setupConnection method and tried again. Eventually the DNS lookup returns an IPv4 address and things proceed smoothly from there.

    This isn't the most elegant solution, but it works.

提交回复
热议问题