Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No route to host" error on iOS

Tags:

ios

I used GCDAsyncUdpSocket to send udp message to discover ssdp service, in iOS reported "No route to host" this error,but there is no problem in the simulator above can be found in service, is that how it happened? I searched a lot of information, but no discovery could help me.

like image 695
HelloWorld Avatar asked Nov 12 '22 20:11

HelloWorld


1 Answers

I've run into the same thing. Of course without your source code we can't help you other than to provide vague guesses. I hope you've fixed it by now and if you recall what the problem actually was, please let us know.

Things to check :

  1. Firewall settings on the host. I was trying to receive messages on my mac book and found that Firewall settings can block the port you chose. Firewall is under system preferences on the 3rd tab.

  2. Use apples Reachability class to make sure you've got an active WIFI/Cell connection to the internet. (here : https://developer.apple.com/library/ios/samplecode/Reachability/Listings/Reachability_Reachability_h.html#//apple_ref/doc/uid/DTS40007324-Reachability_Reachability_h-DontLinkElementID_7 )

  3. You can also use other functions in the Reachability class to let you know if the host is reachable before even bothering to open up a socket.

  4. If the host is your mac and the simulator is on the mac, there isn't much of actual network traffic and then when you run on your phone you are actually using real networking. Be aware of, depending on your networking situation, you may need the external IP address of your host (vs the internal network WIFI address e.g. 192.168.1.4 )

  5. Some people have reported a bug where UDP stops working and you get no route to host messages but for some reason turning on and off airplane mode fixes it. Maybe check out their solution (using keep alive messages ever 30 seconds or so to prevent power management from turning off the cell connection). Here is an example : intermittent "No Route to Host" on iOS, flight mode off then on fixes

like image 149
LawfulEvil Avatar answered Nov 15 '22 05:11

LawfulEvil