Forum Moderators: open

Message Too Old, No Replies

Synchronized Timer

         

Avellar

3:12 pm on Feb 24, 2003 (gmt 0)

10+ Year Member



I'm working on a draft tool to use for madden and fantasy football and such. I've got the whole thing pretty much working, but I'm kinda stuck on one point. I have a JavaScript timer in a frames page and am using a hidden page that refreshes every 10 seconds to check an application variable that indicates whether a pick has been made since the last time the hidden page refreshed. This allows me to force all of the browsers to reset the timers to zero within 10 seconds of the time that someone makes a pick. This will work because the person who is actually on the clock, their timer will force a pick after 3 minutes if they don't pick and I've added a button to the page the admin sees to allow him to force a pick. Problem is, if someone closes the window or hits refresh, their timer is reset. No big deal, we can still use it and the commish can force a pick if he thinks someone has had too much time, but I'd like to find a way to synch the timers up.

My idea was to store the time on the server in an application variable each time a pick was made and when the hidden page updates every 10 seconds, return the offset between that time and current server time. Then update the timer on the client browser according to that offset time. Problem is, I'm not sure how to do to things:

1...How do I find the offset between the last pick time and current time on the server using VBScript?

2...How do I translate that into seconds and minutes to display using JavaScript on the client.

Anybody got an idea or a link to some VBScript time functions for me? I would think I would want to store the time difference as a number of seconds and return that to the browser, then adjust my stopwatch timer to be that many seconds starting from 0.

hakre

11:18 am on Feb 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi avellar,

even if it is possible (use timer(), pass the last creation time if your hidden page on it's refresh back to server and calculate the new offset in that vbscript), you won't be able to synchronize that good because of connection time. you don't know, how long the time will be between the creation of the page and it's display. this could be up to 10 seconds if the connection to your user hangs. this gap you can't close and calculate.

what might be a better solution is to create a timestamp of the browsers time and calculate an offset to your servertime. then this could be synced in javascript on the users page all the time.

Avellar

7:50 pm on Feb 25, 2003 (gmt 0)

10+ Year Member



Hakre,

Thanks, actually, I think for my purposes that may work fine. I'm not really worried about keeping the timers in exact synch. A 10-20 second margin of error is probably acceptable. The main thing is to sort of keep people from closing their browser and opening it back up again or even just hitting refresh to gain time...and to impose some sort of something so that I can say to them, hey, don't worry if your timer goes up to 3:30 seconds or so, but if it hits 4 minutes, something may be wrong and the commish might need to force a pick. I hadn't really thought about the load time problem :) I may need to add a button for the commish to give people extra time by resetting the last pick time to be the current time. Just in case somebody does have a problem and can't load the page or something for a long time.