I need to write a simple ping
method in Cocoa/Objective-C. It also needs to work on the iPhone.
I found an example that uses icmp
, will thi
The code below seems to be working synchronously:
const char *hostName = [@"stackoverflow.com"
cStringUsingEncoding:NSASCIIStringEncoding];
SCNetworkConnectionFlags flags = 0;
if (SCNetworkCheckReachabilityByName(hostName, &flags) && flags > 0) {
NSLog(@"Host is reachable: %d", flags);
}
else {
NSLog(@"Host is unreachable");
}
Note: SystemConfiguration.framework
is required