Re: How to detect no internet connection?
Re: How to detect no internet connection?
- Subject: Re: How to detect no internet connection?
- From: Jens Alfke <email@hidden>
- Date: Mon, 25 Jan 2010 13:58:52 -0800
On Jan 25, 2010, at 1:50 PM, Laurent Daudelin wrote:
What is the best way to detect that there is no internet connection
from my Cocoa app?
SystemConfiguration.framework. It can even send you notifications in
real-time as the network status changes.
Detecting no network would work too but I'd like to be able even if
the Macintosh is connected to a network that it can't reach the
internet. I know I could use a test connection but is there a better
way?
A reasonable request, but the problem is that "reach the internet" is
too vague a question. The main situation where it breaks down is on an
intranet that requires use of a proxy to reach the outside world. In
this case you are literally not connected to the Internet, even with a
1000baseT plug jacked into your computer, even though your web browser
and email work fine.
If on the other hand you just mean "can I ping the router", this will
be true on a home 802.11 network even when the DSL/cable modem is
down, and there are no outside hosts reachable.
Basically you have to decide based on the specific functionality of
your app. In a lot of cases what the app wants to know is "can I reach
my server at foobar.com:12345?", and SystemConfiguration will let you
ask that question. It won't be 100% accurate, though, because it gets
its answer only from consulting the local routing tables, not from
actually sending any packets.
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden