Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Locker

macrumors 6502
Original poster
Aug 22, 2007
291
0
Staffordshire, UK
Hello,

I want an app to check whether it has a connection to a local server (via host-name or IP)... and also check whether it has a connection to the Internet (this can be by checking google.com if needs be).

If anyone could point me towards the easiest way to do this it would be much appreciated :)
 
Okay, so say I have something like:

Code:
if (do shell script "ping host-name") contains "1 packets received" then...

How exactly would I integrate this into a cocoa app? So that the fact it was running that ping was unknown to the user. And... how would it pass the results of the ping back to the cocoa app?

Sorry, I'm new to this :eek:
 
I did do a search in Google. Unfortunately most examples use SCNetworkReachability methods which will return true even if the host isn't responding. Anyone know any alternatives to that? I imagined this would be pretty easy to do...
 
Yeah, you pretty much have to approach this with two layers. SCNetworkReachability is your first layer which tells you if it is even worth trying to hit the network. The second layer is to check the host itself, and the links provided is exactly what you need.

This works well for providing a status mechanism on a server without having to actually open a connection to it.

If you intend to open a connection anyways, you might as well make the connection once SCNetworkReachability says you've got a connection that will work. It's almost always wasted effort to ping a server immediately before opening the connection, as they have similar timeouts for Ping vs TCP connections.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.