需要客户端时间来镜像服务器端时间

时间:2022-05-18 15:13:17

I need client-side time to mirror server-side time. Are there any best practices around this?

我需要客户端时间来镜像服务器端时间。有什么关于这方面的最佳实践吗?

I'm not sure how exactly I would go about making sure the two match.

我不确定我该如何确定这两个匹配。

Thanks!

谢谢!

2 个解决方案

#1


2  

Network Time Protocol has an algorithm for synchronizing time between machines while accounting for network latency.

网络时间协议有一种算法,可以在计算网络延迟的同时在机器之间同步时间。

If you were to implement such an algorithm with AJAX or (even better) websockets, then you would end up with a value holding the differential between local machine time and server time.

如果您使用AJAX或(甚至更好)websockets实现这样的算法,那么您最终会得到一个值,这个值将保持本地机器时间和服务器时间之间的差异。

Any time you did a time calculation on the client side, you could utilize that time differential value to adjust the output to be reasonably close to server time. It's never going to be exact, but you could probably get within 100 milliseconds on most connections.

任何时候在客户端进行时间计算时,都可以使用时间差异值来调整输出,使其与服务器时间相当接近。这永远不会是准确的,但是你可能会在100毫秒内完成大多数连接。

#2


2  

The answer depends upon what you mean, as your phrasing doesn't really give enough info to know why you want the time to be the same across the different machines..

答案取决于你的意思,因为你的措辞并不能提供足够的信息来了解为什么你想让时间在不同的机器上保持一致。

If you mean "I want all of the system clocks to be set to the very same time" then you need to search for stuff related to Network Time Protocol. Google can give you links to intro materials and there is also an overview of NTP on this site. But that's not a Node.js or programming problem...and the answers can be very operating system specific...and if you don't own all of the clients then you are out of luck

如果您的意思是“我希望所有的系统时钟都同时设置”,那么您需要搜索与网络时间协议相关的内容。谷歌可以为您提供介绍材料的链接,在这个网站上也有关于NTP的概述。但这不是节点。js或编程问题…答案可以是非常具体的操作系统…如果你不拥有所有的客户,那你就不走运了

If you mean "I want all events to happen at the same time on all clients even if the system clocks are different" then there is already a question here that has all of these answers.

如果您的意思是“我希望所有事件在所有客户端上同时发生,即使系统时钟不同”,那么这里已经有一个问题有所有这些答案。

Good luck.

祝你好运。

#1


2  

Network Time Protocol has an algorithm for synchronizing time between machines while accounting for network latency.

网络时间协议有一种算法,可以在计算网络延迟的同时在机器之间同步时间。

If you were to implement such an algorithm with AJAX or (even better) websockets, then you would end up with a value holding the differential between local machine time and server time.

如果您使用AJAX或(甚至更好)websockets实现这样的算法,那么您最终会得到一个值,这个值将保持本地机器时间和服务器时间之间的差异。

Any time you did a time calculation on the client side, you could utilize that time differential value to adjust the output to be reasonably close to server time. It's never going to be exact, but you could probably get within 100 milliseconds on most connections.

任何时候在客户端进行时间计算时,都可以使用时间差异值来调整输出,使其与服务器时间相当接近。这永远不会是准确的,但是你可能会在100毫秒内完成大多数连接。

#2


2  

The answer depends upon what you mean, as your phrasing doesn't really give enough info to know why you want the time to be the same across the different machines..

答案取决于你的意思,因为你的措辞并不能提供足够的信息来了解为什么你想让时间在不同的机器上保持一致。

If you mean "I want all of the system clocks to be set to the very same time" then you need to search for stuff related to Network Time Protocol. Google can give you links to intro materials and there is also an overview of NTP on this site. But that's not a Node.js or programming problem...and the answers can be very operating system specific...and if you don't own all of the clients then you are out of luck

如果您的意思是“我希望所有的系统时钟都同时设置”,那么您需要搜索与网络时间协议相关的内容。谷歌可以为您提供介绍材料的链接,在这个网站上也有关于NTP的概述。但这不是节点。js或编程问题…答案可以是非常具体的操作系统…如果你不拥有所有的客户,那你就不走运了

If you mean "I want all events to happen at the same time on all clients even if the system clocks are different" then there is already a question here that has all of these answers.

如果您的意思是“我希望所有事件在所有客户端上同时发生,即使系统时钟不同”,那么这里已经有一个问题有所有这些答案。

Good luck.

祝你好运。