• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About Syncronizing time between clients and a server.

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???]

Cheers,
Nachiket
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic