Synchronizing time between two PCs via TCP/IP, no server

你说的曾经没有我的故事 提交于 2019-12-12 17:19:58

问题


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


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/4304480/synchronizing-time-between-two-pcs-via-tcp-ip-no-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!