Author Topic: low latency javascript clock synchronized to server time  (Read 2622 times)

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
low latency javascript clock synchronized to server time
« on: October 17, 2012, 03:46:50 PM »
So i'm working on an app that needs the client browser to trigger some javascript events on a fairly precise timeline in coordination with other browsers.  I wrote a little function that grabs the server time via AJAX.  For production, I can be off buy a tiny bit but I'm trying to get it as close as possible by shaving off milliseconds of lag where possible so it accounts for the connection time lost talking to the server and applies that latency to the offset value.  Once the offset value is determined, the client can use the system time + the offset to trigger events at the pre-determined and coordinated times.

It seems to be working pretty well, but I notice that sometimes when I have it running on multiple devices, it looks off by up to a half second or so.  Anyone care to test?  The URL is http://micahj.com/code/syncOffset/  If you could, please open that link in couple browsers and maybe  a smartphone which will have a different system time than your browser, then let me know if the time seems to be accurate without noticeable phase difference.
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

JaWiB

  • definitelys definately no MacGyver
  • Jackass V
  • Posts: 1443
  • Karma: +57/-4
Re: low latency javascript clock synchronized to server time
« Reply #1 on: October 17, 2012, 04:34:55 PM »
Seems to be about .5s ahead in firefox compared to chrome for me.

kermi3

  • ?
  • Ass Wipe
  • Posts: 5513
  • Karma: +56/-22
Re: low latency javascript clock synchronized to server time
« Reply #2 on: October 17, 2012, 04:36:34 PM »
Well under half a second on both my thinkpad and my iPhone 5
govtcheez03:  i kind of look for it - i seek out stupidity and annoy it until it either gets better, gets banned, or goes away on its own

Steve

  • This 49%er supports Romney
  • Just a Jackass
  • *
  • Posts: 16120
  • Karma: +31/-410
  • Mr. Mom
Re: low latency javascript clock synchronized to server time
« Reply #3 on: October 17, 2012, 06:06:59 PM »
chrome, ff, android was dead on
hey ethic if you and i were both courting lily allen..... oh wait, which one of us has a relationship that lasted more than the bus ride home?

Jake

  • Jackass In Charge
  • Posts: 8651
  • Karma: +83/-18
Re: low latency javascript clock synchronized to server time
« Reply #4 on: October 17, 2012, 07:40:42 PM »
about 2 seconds off on chrome.
Do not follow where the path may lead. Go instead where there is no path and leave a trail.

charlie

  • Jackass In Charge
  • Posts: 7902
  • Karma: +84/-53
Re: low latency javascript clock synchronized to server time
« Reply #5 on: October 17, 2012, 08:52:36 PM »
Pretty much exact for me on Chrome and Firefox on my desktop and Safari on my iPod.

kermi3

  • ?
  • Ass Wipe
  • Posts: 5513
  • Karma: +56/-22
Re: low latency javascript clock synchronized to server time
« Reply #6 on: October 17, 2012, 09:00:47 PM »
My think pad was running chrome too btw
govtcheez03:  i kind of look for it - i seek out stupidity and annoy it until it either gets better, gets banned, or goes away on its own

jkim

  • Jackass In Charge
  • Posts: 3290
  • Karma: +106/-12
Re: low latency javascript clock synchronized to server time
« Reply #7 on: October 17, 2012, 11:35:45 PM »
Faster on my phone than on my desktop with Chrome.