2

I've looked at Reachability sample from apple and another sample from "Iphone developer's cook book"

Here are steps to test ip/port reachability

  1. construct sockaddr_in variable with given ip/port.
  2. call SCNetworkReachabilityCreateWithAddress with the address
  3. call SCNetworkReachabilityGetFlags and see if kSCNetworkFlagsReachable is set.

I find that whatever valid(valid-range) ip/port I put to test, my code says it's reachable even though they are not actually reachable when i ping or telnet test.
(I have seen other SO posts where reachability test to specific ip always succeed) Reachability reachabilityWithAddress does not work

is SCNetworkReachability.. call only checks the validity of argument(ip address or hostname)? ie, do they actually send a packet(or do connect) to the given address to test reachability?

I can implement the async connect with timeout myself, but it's subtle matter how long the timeout should be not to be rejected by apple reviewers.(I am worried if it takes too long, apple reviewers might think my app is not handling network reachability at all)

Thank you

Community
  • 1
  • 1
eugene
  • 39,839
  • 68
  • 255
  • 489
  • 1
    http://stackoverflow.com/questions/5874445/ios-network-reachability-doesnt-seem-to-be-working/5875059#5875059 Reachability is not going to help you with that. – Joe May 04 '11 at 16:51
  • @joe: ah, thanks, what does "being able to leave the local device" mean? it's a network question I guess. Does it mean ip is routed to other computer but doesn't know whether it will succeed in getting to the address? (because local routing table probably don't have enough routing info on arbitrary ip address and will forward to other host I suspect) – eugene May 05 '11 at 04:08
  • @joe: apple won't reject app for not detecting host's up/down? just verifying internet connection being up is fine? – eugene May 05 '11 at 07:37
  • 1
    Apple wants for your app to elegantly fail if there are any network related issue, checking to see if internet is available is the first step, the next step is to properly handle errors returned by your server (ie 400, 404 http status codes, setting a decent timeout) – Joe May 05 '11 at 12:27

1 Answers1

3

To answer your question based on the comments above, according to the SCNetworkReachability Reference

A remote host is considered reachable when a data packet, sent by an application into the network stack, can leave the local device. Reachability does not guarantee that the data packet will actually be received by the host.

This will not be able to check the status of your server but just make sure it can get a data packet out.

Apple wants for your app to elegantly fail if there are any network related issue, checking to see if internet is available using Reachability is the first step. If Reachability fails you can assume that you wont be able a server and alert the user immediately. The next steps are to properly handle errors returned by your server such as a 400 bad request, 404 file not found, setting a reasonable timeout, and not blocking the UI during long downloads while showing some sort of status indicator.

Joe
  • 56,979
  • 9
  • 128
  • 135
  • Reachability then, is poorly named. It's misleading...reachability's check for a hostname implies to me that the iphone can ping a host of my choice AND see if that host replies. All reachability does, then, is reflect in a programmatic way whether your wifi icon or 4G icon is showing on the screen (minus times when GUI icons don't reflect the true underlying network status). Reachability means that the iPhone is online, and ready for action. Nothing more. It doesn't help you fig out the case where your company's server is down, while a 24-7 site like google.com is up. Is that correct? – user798719 Jun 08 '13 at 21:49