将客户端时间与服务器时间同步,即使客户端应用程序独立于本地计算机时间

发布于 2024-09-08 03:53:30 字数 320 浏览 4 评论 0原文

好的,那么情况如下。

我有一个提供游戏服务的服务器,来自服务器的特定命令会发送下一轮游戏何时开始的时间戳。为了在所有连接的客户端上完美同步,我还有一个 webbservice,它返回服务器当前时间的时间戳。

我所知道的是:发送请求和收到答复之间的时间。 我不知道的是:延迟在哪里,客户端处理或服务器处理或带宽问题。

在这里获得合理结果的最佳实践是什么。我想 GPS 一定以某种方式解决了这个问题,但我一直找不到好的模式。

我现在所做的是将请求延迟的一半添加到服务器时间戳,但这还不够好。这可能是因为发送和接收之间的时间可能高达 11 秒。

建议?

Ok, so the situation is as follows.

I have a server with services for a game, a particular command from the server sends a timestamp for when the next game round should commence. To get this perfectly synced on all connected clients I also have a webbservice that returns a timestamp of the servers current time.

What I know: the time between request sent and answer recieved.
What I dont know: where the latency lies, on client processing or server processing or bandwidth issues.

What is the best practice to get a reasonable result here. I guess that GPS must have solved this in some fashion but I´ve been unable to find a good pattern.

What I do now is to add half the latency of the request to the server timestamp, but it's not quite good enough. This may have to do that the time between send and recieve can be as high as 11 seconds.

Suggestions?

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

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

发布评论

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

评论(2

最美的太阳 2024-09-15 03:53:30

有许多常见的解决方案可以在机器之间同步时间,包括由 NTPD 和 RTP 完成的正确 PLL 实现。如果您可以更改计算机的当地时间,这对您很有用。如果不是,也许您应该或多或少地做您所做的事情,但在延迟不合理的地方删除同步点。

There're many common solutions to sync time between machines, including correct PLL implementation done by NTPD with RTP. This is useful to you if you can change machine's local time. If not, perhaps you should do more or less what you did, but drop sync points where the latency is unreasonable.

美羊羊 2024-09-15 03:53:30

最佳实践通常是不同步绝对时间,而是使用相对时间。

The best practice is usually not to synchronise the absolute times but to work with relative times instead.

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