Re: Efficient method of checking connectivity
Re: Efficient method of checking connectivity
- Subject: Re: Efficient method of checking connectivity
- From: Ricky Sharp <email@hidden>
- Date: Tue, 01 Jun 2004 11:36:30 -0500
On Tuesday, June 01, 2004, at 04:43AM, Quinn <email@hidden> wrote:
>
At 19:06 -0500 30/5/04, Ricky Sharp wrote:
>
>Is there any more efficient method of determining connectivity to
>
>the internet?
>
>
We introduced new connectivity APIs in Mac OS X 10.3 that allow you
>
to be notified asynchronously (out of the runloop) when connectivity
>
to a host changes. Look in the headers for
>
SCNetworkReachabilityCreateWithName and its associated routines.
Hmm. This is not working for me.
I started with a Carbon App project in Xcode 1.2 and modified it to include my callback:
static void MyReachabilityCallback (SCNetworkReachabilityRef inTarget,
SCNetworkConnectionFlags inFlags, void* ioInfo)
{
int x = inFlags;
}
and the following lines in main before the nibs are created/loaded:
OSStatus err;
SCNetworkReachabilityRef reachabilityRef = SCNetworkReachabilityCreateWithName (
kCFAllocatorDefault, "www.apple.com");
if (reachabilityRef != NULL)
{
SCNetworkReachabilityContext reachabilityContext;
BlockZero (&reachabilityContext, sizeof (SCNetworkReachabilityContext));
if (SCNetworkReachabilitySetCallback (reachabilityRef, MyReachabilityCallback,
&reachabilityContext))
{
int x = 0;
}
}
I put breakpoints on the two "int x = " lines and I always got to the one in main (proving I installed the callback correctly), but my callback was never called.
I even went into the Network Port Configurations pane of the Network system prefs panel to disable/enable "Built In Ethernet", but the callback wasn't called either.
Seems to be two issues here:
First, in reading the API comments, it states that the callback is called when things change. Thus, I don't think this will be a good solution for me anyway because I need to know the initial state of the network and not necessarily when it changes.
Second, the callback should have been called when the network status changed. I'll test this when I get home (where I have dialup access). At my day job, we're always on a LAN.
Did I code this incorrectly? Should the callback have been called when I disabled "Built-In Ethernet"?
Thanks,
Rick Sharp
Instant Interactive(tm)
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.