• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

About Syncronizing time between clients and a server.  RSS feed

Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Champions,
[I am having bit trouble with trusting my solution.. Need your help to make it reliable]
[I am not having much knowledge about low level details of Computer Systems, but i am good software developer ]

Server App talks with Multiple client Apps...And client apps can get disconnect (wireless network).. But they will keep working..
After say 5 hours, network is available.. now all client apps will commit data (commands - work done while disconnected) to the server and server will organize it based on time.

For this i have implemented SNTP as application component. (And i made sure server and client are not running time service)
And client will commit commands after setting timestamps relative to Server's (currently using System.currentTimeMillis() will go for System.nanoTime()).
Clients will get server time difference (SNTP Protocol) it at time of login (At the time of login, Client must be in network).

I want to know, that is it okay to rely on computer's internal clock???, [as client will not be able to sync for 5 hrs.]
[i don't want millisecond accuracy, Up to 1 second or 2 is okay.]

I think, it is generic issue....Is there any framework or project available which can help in this???]

Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont see getting any replies here. Will move it to General Computing
Ranch Hand
Posts: 433
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm... the worst-case-scenario would be that the user comes to the brilliant idea to adjust the time on his computer. So the answer to your question, if you can rely on the internal clock is: no! But to be honest I also don't have a bullet-proof solution. I would probably go with you solution and would add an extra thread, that would start counting the seconds as soon as the computer is offline and checks, as it becomes online again, if there are dramatic differences between the seconds counted in the thread and the time-difference between offline and reconnect from the internal clock. If there's a huge gap between those two values, you know you can't trust the timestamps.
But I don't know if this method I accurate enough, especially if the cpu has a high load during the offline-period and the thread is not able to count *exactly* one second. If this would give you trouble Suns Java Real-Time System might be solution (http://java.sun.com/javase/technologies/realtime/index.jsp).

Due to the fact you haven't mentioned what kind of data you are proceeding a few questions: What happens if the data of one client is lost? What happens if the order is not correct? And is there a chance to increase the intervall to, let's say, 10 seconds?
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!