Re: How can I get information of network disconnection
Re: How can I get information of network disconnection
- Subject: Re: How can I get information of network disconnection
- From: Quinn <email@hidden>
- Date: Fri, 6 Nov 2009 10:03:52 +0100
At 14:52 +0530 6/11/09, Rahulkumar Tibdewal wrote:
To: "email@hidden" <email@hidden>,
"email@hidden" <email@hidden>,
"email@hidden" <email@hidden>
Please don't cross post to N mailing lists. I don't read the other
lists, so I won't see the answers that other folks post to them. You
may even have got an answer on another list, which means I'm wasting
my time writing up this response. *shrug*
Is there any way I can receive signal in my code on server side,
which will tell me that network is disconnected?
Yes. The approach you take depends on your goals. If you want to
monitor a specific connection (that is, your server has a connection
open to a client and you want to clean up that connection quickly if
the network over which it's running goes away), you can do this with
System Configuration framework. Get the address of each endpoint of
the connection and use SCNetworkReachabilityCreateWithAddressPair to
monitor it. Alternatively, if you use a high-level API
(CFSocketStream, or anything layered on top of it), the system will
do this for you.
OTOH, if you just want to monitor your server's listening socket,
things get a little more complex. In general I recommend that you
listen on INADDR_ANY, in which case your server will accept incoming
connections from any interface. At that point monitoring gets
difficult because you have to take all interfaces into account (if
the user disconnects the Ethernet, you might still be able to accept
connections on the AirPort; and if the user powers off AirPort, you
will still be able to accept connections via loopback). In
situations like this, I'll need a more comprehensive description of
your overall goal before I can post any specific suggestions.
Finally, if you haven't read TN1145 "Living in a Dynamic TCP/IP
Environment", you should. It's an old one but a good one!
<http://developer.apple.com/legacy/mac/library/technotes/tn/tn1145.html>
S+E
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
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