iphone - How to write a simple Ping method in Cocoa/Objective-C -
I have to write a simple ping method in Cocoa / Objective-C also have to work on the iPhone is.
I found an example that uses ICMP , will it work on the iPhone?
I have a solution by using NSNetServices on the tilt, is this a good idea?
The method requires only ping host is down or unrecoverable.
The code below seems to work in a synchronous way:
< Code> const char * hostName = [@ "stackoverflow.com" cStringUsingEncoding: NSASCIIStringEncoding]; SCNetworkConnectionFlags Flags = 0; If (SCNetworkCheckReachabilityByName (hostname, & amp; flag) & amp; amp; amp; amp; and & amp; flag & gt; 0) {NSLog (@ "host is unreachable:% d", flags); } And {nslog (@ "host is not reachable"); } Note: SystemConfiguration.framework is required
Comments
Post a Comment