Reputation: 2942
I'm using NSURLConnection
to access a web service (on a .local
host). When I access the host by hostname, I'm seeing a delay of 5+ seconds, but when I access it by IP, the connection completes almost instantly.
Running the app on an actual iPhone, instead of the simulator, does not show any delays at all (testing was done on the same network connection). So this seems to be a problem specific to the iOS Simulator or OS X.
I'm able to simulate the problem using the following terminal commands:
nslookup webservice.myhost.local
(which is fast)
dscacheutil -q host -a name webservice.myhost.local
(shows the delay)
When analyzing the network traffic using Wireshark of the dscacheutil
command, I'm seeing several Standard query AAAA
requests which are marked red and get an empty response. Once these are done, I see a Standard query A
request which has a response containing the correct IP address. The AAAA requests take up about 5 seconds, which would explain the delay.
Upvotes: 5
Views: 2447
Reputation: 36
For anyone else who stumbles across this issue... I myself had to disable IPv6 on my machine to avoid the hang in the simulator while IPv6 fails. I did so following these instructions: https://discussions.apple.com/message/18097613#18097613
Which were to:
"To disable IPv6 in OS X Lion, you will need to use the Terminal.
Applications > Utilities > Terminal
To determine what are all of your Mac's network interfaces are, issue the following command: networksetup -listallnetworkservices
To disable IPv6 for wireless, issue the following command: networksetup -setv6off Wi-Fi;
To disable IPv6 for Ethernet, issue the following command: networksetup -setv6off Ethernet
To re-enable IPv6, use -setv6automatic instead"
Upvotes: 1
Reputation: 45
This answer solved the problem for me. (Create an IPv6 ::1 loopback entry to go along with each 127.0.0.1.)
Upvotes: 2
Reputation: 339816
Does the web service perhaps have IPv6 enabled and you can't use that from the simulator?
I see this on OSX for example when running a local IPv4 only DNS service - if I run dig @localhost
is hangs for some seconds until the initial IPv6 connection times out, and then it tries IPv4.
Upvotes: 4