FROM : Jens Alfke
DATE : Sat May 24 23:25:54 2008
On 23 May '08, at 11:11 PM, Mike wrote:
> Why does [ NSURLConnection canHandleRequest: ] return YES even if I
> turn off all my network connections? I thought this method was
> supposed to be used for preflighting connection requests?
No, it just tells you whether there's support for that URL scheme
(http:, ftp:, etc.)
If you want to tell whether the host is reachable, you need to use the
System Configuration API — look up the docs for
SCNetworkCheckReachabilityByName. (I also just noticed
CFHostGetReachability, which looks like a higher-level interface that
might be easier to call.)
Even this just checks the system's network interfaces and routing
tables to decide whether the kernel knows how to route a packet
towards that address — it does _not_ actually try to contact the
server, so it can't tell you if there's a broken gateway, or the
server is down, or it's not listening on the port you want to connect
to, etc.
—Jens
DATE : Sat May 24 23:25:54 2008
On 23 May '08, at 11:11 PM, Mike wrote:
> Why does [ NSURLConnection canHandleRequest: ] return YES even if I
> turn off all my network connections? I thought this method was
> supposed to be used for preflighting connection requests?
No, it just tells you whether there's support for that URL scheme
(http:, ftp:, etc.)
If you want to tell whether the host is reachable, you need to use the
System Configuration API — look up the docs for
SCNetworkCheckReachabilityByName. (I also just noticed
CFHostGetReachability, which looks like a higher-level interface that
might be easier to call.)
Even this just checks the system's network interfaces and routing
tables to decide whether the kernel knows how to route a packet
towards that address — it does _not_ actually try to contact the
server, so it can't tell you if there's a broken gateway, or the
server is down, or it's not listening on the port you want to connect
to, etc.
—Jens
| Related mails | Author | Date |
|---|---|---|
| Mike | May 24, 08:11 | |
| Sherm Pendley | May 24, 13:25 | |
| Jens Alfke | May 24, 23:25 |






Cocoa mail archive

