views:

466

answers:

3

I'm looking to implement a Ping class in Cocoa-Touch. From the googling I have done and old c code I have looked at, it seems using the ICMP protocol is the best way to go.

I guess my question is, is ICMP supported in the iPhone SDK, and if not, is there anything in the CoreFoundation Network classes I could use instead? I have had a look at CFHost and CFHostStartInfoResolution(host, kCFHostReachability, &error) but that is more to check if a host exists rather than get the time to respond etc.

A: 

Not sure about the CFNetwork stuff, but don't forget that you still have all the usual BSD networking stuff at your disposal too.

Mike Akers
On the iPhone too? Awesome
KiwiBastard
+1  A: 

Yep, you can theoretically do this. However, the last time I checked you needed to be running as root to get access to the 'raw' BSD socket required for sending ICMP traces. This is true on the Mac, at least, so I'd assume it's the same on the iPhone.

You might want to take a look at the SystemConfiguration framework and the SCReachability APIs as an alternative. These are all asynchronous, so you can potentially keep track of the time that takes to get an idea of the network latency.

Jim Dovey
Actually, this was only true up until OSX 10.2
Denis Hennessy
A: 

did you get it work?

singh is singing