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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With