通过 TCP/IP 同步两台 PC 之间的时间,无需服务器
我有两台通过 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你不能使用NTP服务器,你必须自己编写它。
如果您不需要太精确,那么您就完成了。如果您需要更高的精度,则需要估计数据发送和到达之间的时间损失,这并不是微不足道的。
If you can't use NTP server you have to write it by yourself.
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.
一种低技术解决方案可能是在需要更新的计算机上执行命令
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.
是否可以指定其中一台机器作为 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