• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting network change
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting network change


  • Subject: Re: Detecting network change
  • From: Josh Graessley <email@hidden>
  • Date: Thu, 23 Oct 2008 14:38:40 -0700


On Oct 23, 2008, at 2:14 PM, Shawn Erickson wrote:

On Thu, Oct 23, 2008 at 1:31 PM, Greg <email@hidden> wrote:

On Oct 21, 2008, at 4:56 PM, Jens Alfke wrote:

Use SystemConfiguration.framework to register for notifications when the
network configuration changes. There's sample code for both Mac and iPhone
showing how to use it.


Note that this isn't magic — it will tell you if the user unplugged
Ethernet from the computer, but not if he unplugs the router's Ethernet
connection, or if workmen down the street accidentally cut his cable, or the
ISP's routers go down, or your server crashes, etc. In other words, it tells
you about things that happen on the computer, not elsewhere along the
network.


—Jens

OK, I've finally had a chance to work on this some, and I found two sample
projects:


      SimpleReach (normal) and Reachability (iPhone specific)

Neither example detects when the "network changes". They seem to detect
when the network goes down, or up, but not if I hop from say, one access
point to another (thereby getting a different IP address), which is what I
need to be able to do.


After looking through the SystemConfiguration documentation a bit, as well
as the sample code, I'm not sure if I saw anything that would enable me to
do this...

You have the ability to watch values in the dynamic store and get notifications (callbacks) when they change. Review the document I linked for information about notifications and also the schema so you know what keys to watch / probe.

Also look at the following API...

SCDynamicStoreCreateWithOptions / SCDynamicStoreCreate
SCDynamicStoreCreateRunLoopSource
SCDynamicStoreSetNotificationKeys

The SCDynamicStore APIs are available on the desktop but not on the iPhone/iPod Touch.


If you use SCNetworkReachabilityCreateWithName or SCNetworkReachabilityCreateWithAddress for general reachability and follow up with SCNetworkReachabilityCreateWithAddressPair when you have established a connection, SCNetworkReachabilityCreateWithAddressPair will notify you when the local address is no longer useful. If you have access to the socket, you can use getsockname and getpeername to get the values for SCNetworkReachabilityCreateWithAddressPair. If you're using one of those fancy high level frameworks, you may have no access to the socket. Ideally there would be events directly on the socket to let you know about changes that may be relevant or SCNetworkReachabilityCreateWithSocket that would look at the state of the connected socket and figure out the nitty gritty details.

-josh

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Detecting network change
      • From: Greg <email@hidden>
References: 
 >Detecting network change (From: Greg <email@hidden>)
 >Re: Detecting network change (From: Jens Alfke <email@hidden>)
 >Re: Detecting network change (From: Greg <email@hidden>)
 >Re: Detecting network change (From: "Shawn Erickson" <email@hidden>)

  • Prev by Date: Re: Detecting network change
  • Next by Date: Re: Detecting network change
  • Previous by thread: Re: Detecting network change
  • Next by thread: Re: Detecting network change
  • Index(es):
    • Date
    • Thread