It's probably only worth it to have the server ping the client if you're waiting for something to happen on the server. If that's the case, then take a look at comet approaches. Otherwise, you're probably not going to do better than running a local timer on the client, IMO.
And you're right--there's no perfect synchronization across any network. If you're interested in learning more about this problem in general, check out articles on ntp, the network time protocol. Jared On Monday, April 4, 2011, Dmitry Pashkevich <[email protected]> wrote: > Hi Peter! > > To my knowledge it's impossible to build a 100% accurate timer in JS since > the language is asynchronous in it's nature: there's no guarantee that an > event scheduled to occur at some point in time would execute exactly at that > moment because there may be other pending items in the event loop. > I suggest you read 2 really good insightful articles from John Resig: > http://ejohn.org/blog/how-javascript-timers-work/ > http://ejohn.org/blog/accuracy-of-javascript-time/ > They explain why there is a precision issue in javascript timers and > important difference between setTimeout and setInterval functions. > > You can, however, achieve some level of precision or at least assess the > error you get by taking the mentioned issues into account. Take a look at > javascript benchmarks like http://jsperf.com/ > > I hardly doubt that your approach on contacting the server to get the time is > viable because the network latency that will seriously affect your measurings > is completely unpredictable. > > Please correct me anyone if I am wrong. > > Dmitriy. > > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected] > -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
