tags:

views:

777

answers:

6

I am writing an application that requires accurate timing. After asking this question, I have decided to investigate using NTP or maybe Simple NTP.

Is there any open source implementation of these protocols for the iPhone? So far I have managed to find a broken link. I am also aware that NTP has a C reference implementation, so I am trying to see how much effort it would require to make it work on the iPhone.

Update: I thought I had a working link, but it is to the Wayback Machine, which only saves text, not files link that works.

+1  A: 

I would probably start by pulling code from OpenNTPD.

Rob Napier
+2  A: 

If you're not developing a commercial application, peek at the linux source.

http://packages.ubuntu.com/source/lucid/ntp

Andrew B
Thanks, but the application is commerical
Casebash
A: 

If you need to use NTP, but don't want to trust the iPhone (or iPod's) clock, you can always just use sockets (or Cocoa streams) and query the server yourself. It's one of the simplest network transactions out there.

Cocoa Streams

Steve Melvin
Beware, though, that network latency can vary *wildly* over time (depending on network load, signal quality, EDGE/3G vs. WiFi, etc). Probably not a concern if you just need to be accurate to within a few seconds, but more troublesome if you careabout milliseconds.
Andrew Medico
A: 

I don't know what application you're creating, but if trusting the clock is a critical feature of its security or (in the case of game) cheat prevention, etc, then you need to be very careful of open protocols like NTP-- a cheater could do a man-in-the-middle on your NTP request and tell your app what he wanted you to hear.

If this is potentially a concern, you'll want to build your own trustable source of truth for time into your server (e.g. build your own time service, and sign your responses with PK crypto), and set your app's internal clock to that within some acceptable clock skew.

quixoto
+1  A: 

Since you are developing a commercial app, if all else fails, RFC 2030 describes the SNTP protocol. I have no information on commercially available libraries that do not require a background task, which the iPhone won't let you use.

Mike DeSimone