iPhone 的网络时间协议
我正在编写一个需要精确计时的应用程序。在提出这个问题后,我决定使用 NTP 或也许进行调查简单的 NTP。
iPhone 上有这些协议的开源实现吗?到目前为止,我已经设法找到一个 损坏的链接。我还知道 NTP 有一个 C 参考实现,所以我想看看有多少让它在 iPhone 上运行需要付出努力。
更新:我以为我有一个工作链接,但它是指向 Wayback Machine 的,它只保存文本,而不保存文件 有效链接。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
有一个名为 ios-ntp 的小型 iOS 库。我过去在一个项目中使用过它,看起来效果相当不错。
截至 2013 年中期,原始的 ios-ntp 项目有一些缺失,所以我将原始的 svn 存储库镜像到了 github。您可以在此处查看代码的工作版本: https://github.com/jessedc/iOS- ntp
There's a small iOS library named ios-ntp. I have used it in one project in the past and it seemed to work reasonably well.
As of mid 2013 the original ios-ntp project has a few missing pieces, so I have mirrored the original svn repository to github. You can checkout out a working version of the code here: https://github.com/jessedc/iOS-ntp
我可能会从 OpenNTPD 提取代码开始。
I would probably start by pulling code from OpenNTPD.
如果您不开发商业应用程序,请查看 Linux 源代码。
http://packages.ubuntu.com/source/lucid/ntp
If you're not developing a commercial application, peek at the linux source.
http://packages.ubuntu.com/source/lucid/ntp
如果您需要使用 NTP,但又不想信任 iPhone(或 iPod)时钟,您始终可以只使用套接字(或 Cocoa 流)并自行查询服务器。这是最简单的网络交易之一。
可可流
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
我不知道您正在创建什么应用程序,但如果信任时钟是其安全性或(在游戏中)作弊预防等的关键功能,那么您需要非常小心开放协议,例如 NTP- - 作弊者可以对您的 NTP 请求进行中间人操作,并告诉您的应用程序他想让您听到的内容。
如果这可能是一个问题,您将需要在您的服务器中构建您自己的可信时间真实来源(例如构建您自己的时间服务,并使用 PK 加密签署您的响应),并将应用程序的内部时钟设置为一些可接受的时钟偏差。
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.
由于您正在开发商业应用程序,如果其他方法都失败,RFC 2030 描述了 SNTP协议。我没有关于不需要后台任务的商用库的信息,iPhone 不允许你使用后台任务。
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.
您可以使用该开源: https://github.com/huynguyencong/NHNetworkTime
并使用:
You can use that open source: https://github.com/huynguyencong/NHNetworkTime
And use: