如何比较 Iphone 和(网络)服务器之间的时间?

发布于 2024-10-22 03:10:45 字数 299 浏览 1 评论 0 原文

我有一个由服务器组成的应用程序,它偶尔向 iPhone 发送消息。两个设备之间的延迟对于问题域很重要 - 如果消息到达的时间不到一秒,则一切正常;如果时间超过 5 秒,则几乎肯定有问题。服务器端消息带有服务器时间的时间戳。

使用蜂窝数据连接,我们偶尔会看到延迟,但我们无法量化它们,因为无法保证 Iphone 的时钟与服务器同步;在我们的测试手机中,我们看到不同运营商的不同时间。

有没有一种简单的方法可以同步iPhone和服务器之间的时间?我查看了 (S)NTP,这似乎是正确的方法。

还有其他选择吗?我们只需要精确到秒,而不是毫秒。

I have an application made up of a server which sends occasional messages to Iphones. The latency between the two devices is important to the problem domain - if it takes less than a second for the message to arrive, everything's fine; if it takes more than 5 seconds, there's almost certainly a problem. The server-side messages are time stamped with the server time.

Using the cellular data connection, we see occasional delays, but we can't quantify them, because there's no guarantee that the Iphone's clock is synchronized with the server; one our test phones, we see different times for different carriers.

Is there a simple way to synchronize time between the Iphone and the server? I've looked at (S)NTP, which seems to be the right way to go.

Any alternatives? We only need to be accurate within seconds, not milli seconds.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ双果 2024-10-29 03:10:45

我不确定确切的情况是什么,所以这可能不是一个解决方案,但是:

假设您想以设定的时间间隔(由服务器决定)计算出手机和服务器之间的延迟(并且仅此) )。还假设错误检查是在服务器端完成的,您可能会采用“ping”方法,而不是同步时钟。

  • 服务器 ping 客户端 iPhone,并启动秒表。
  • 客户端立即 ping 服务器。
  • 一旦客户端 ping 到达服务器,服务器就会停止秒表并检查时间。

如果我误解了你的问题,抱歉。

I'm not sure what the exact situation is, so this may be a non-solution, but:

Presuming that you want to figure out the latency between the phone and the server (and only this) at set intervals (decided by the server). Presuming also that the error checking is done server-side, instead of synchronizing clocks, you might go with a "ping" approach.

  • Server pings client iPhone, and starts a stopwatch.
  • Client immediately pings server.
  • As soon as client ping reaches server, server stops the stopwatch and checks the time.

If I misunderstood your problem, apologies.

暮年慕年 2024-10-29 03:10:45

嗯,一个有点简单的解决方案是,您可以让手机告诉服务器它们在不同时间的时间,并保存一个增量数据库表。然后将报告的时间戳调整为服务时间 r +/- 增量。据我所知,iPhone 已同步到运营商的时间服务器。另一种可能性是让电话和服务器每天查询公共时间源。一天内时间不太可能有太大变化。

Well, a somewhat simplistic solution is that you could have the phones tell the server what time they have at various times and keep a database table of deltas. Then adjust your reported timestamp to the serve's time r +/- the delta. iPhones are synced to the carrier's time server to the best of my knowledge. The other possibility is to have both the phone and server query a common time source on a daily basis. It's unlikely that the time would vary much over a single day.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文