通过 TCP/IP 同步两台 PC 之间的时间,无需服务器

发布于 2024-10-05 04:15:40 字数 142 浏览 6 评论 0原文

我有两台通过 LAN 连接的 PC。当用户更改一台机器上的时间(通过我的应用程序)时,我希望第二台机器上的时间也能更新(或者第二台机器可以轮询第一台机器)。没有服务器,没有互联网。最好的方法是什么?

操作系统:XP嵌入式。
框架:.Net 3.5

I've got two PCs connected by LAN. When the user alters the time (via my application) on one, I'd like the time on the second to be updated too (or the second machine could poll the first). There's no server, no internet. What's the best way to do this?

OS: XP embedded.
Framework: .Net 3.5

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

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

发布评论

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

评论(3

空城仅有旧梦在 2024-10-12 04:15:40

如果你不能使用NTP服务器,你必须自己编写它。

  1. 这两个应用程序都实现 WCF 服务,并且是另一个应用程序的一个客户端;
  2. 本地时间被修改的应用程序通知对方并发送 DateTime;
  3. 接收更新的 DateTime 的应用程序会更改本地时间(但请注意,您的应用程序将需要更高的权限才能执行此操作,因为您必须通过非托管代码来执行此操作);

如果您不需要太精确,那么您就完成了。如果您需要更高的精度,则需要估计数据发送和到达之间的时间损失,这并不是微不足道的。

If you can't use NTP server you have to write it by yourself.

  1. The two application both implements a WCF service and are one client of the other;
  2. The application that have its local time modified notifies the other and sends a DateTime;
  3. The application that receives the updated DateTime changes local time (but be aware that your application will need higher privilege to do this because you have to do it via unmanaged code);

If you don't need much precision you are done. If you need greater precision, you will need to estimate the time lost between the data sending and arrivals and is not trivial.

執念 2024-10-12 04:15:40

一种低技术解决方案可能是在需要更新的计算机上执行命令NET TIME \\[OtherPC] /SET

您可以将机器设置为以一定的时间间隔调用此函数。

请注意,我只在普通 Windows 机器上尝试过它,但我认为它也适用于嵌入式。

编辑:环顾四周,XP Embedded 似乎可能支持 WMI,如果支持的话,并且它确实有 Win32_OperatingSystem 类,它是 SetDateTime 方法,您的应用程序可以向远程电脑发出该调用,您可以避免轮询更改。

A low tech solution might be to execute the command NET TIME \\[OtherPC] /SET on the machine that needs to be updated.

You could possibly set the machine up to call this at a certain interval.

Please note, I've only tried it on normal windows machines, but I think it would also work on embedded.

Edit: Looking around it seems like XP Embedded might support WMI, if it does and it does have the Win32_OperatingSystem class and it's SetDateTime method, your app could make that call to the remote pc and you could avoid having to poll for changes.

尸血腥色 2024-10-12 04:15:40

是否可以指定其中一台机器作为 NTP 服务器?因此使用标准的 NTP 服务器系统,这样您就不必编写自己的系统。

虽然我不熟悉 XPe 这个链接 有时间吗? 似乎拥有所有必需的流行语

Is it possible to designate one of the machines as an NTP server? and hence use a standard NTP server system so you don't have to write your own.

Although I am not familiar with XPe this link Got the time? seems to have all the required buzzwords

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