Page 1 of 1

How to implement "Real-time" event updates on a website

Posted: Fri Dec 17, 2010 3:00 pm
by emmbec
Hi guys, I was wondering if anyone of you know how to implement something similar to what the guys from nailbidder.com have in regards of updating the current bid. It looks like as soon as someone performs a bid, the price gets updated and the time remaining for the bid also gets updated (Once a bid is close to ending). How do they do that? I mean, how can they update the bid status and everything when someone else other than the person who is viewing the website is submitting information? Specially the time, since they are showing seconds and it looks like it never gets too de-synchronized from what I see...

Thanks!

Re: How to implement "Real-time" event updates on a website

Posted: Fri Dec 17, 2010 3:08 pm
by Technical
Most likely they use JS framework to periodically requesting information with AJAX requests. Prototype framework has special class for it - Ajax.PeriodicalUpdater

Re: How to implement "Real-time" event updates on a website

Posted: Fri Dec 17, 2010 3:15 pm
by Technical
They key is using setTimeout() method.

Re: How to implement "Real-time" event updates on a website

Posted: Sat Dec 18, 2010 12:50 pm
by Jonah Bron
Technical wrote:They key is using setTimeout() method.
Actually, setInterval would be better. For the bidding, just use setInterval to periodically call the server asking for the latest bid. For the time, just keep the time with the client's clock, and re-synchronize at the same time as when you update the bid.

But beware, do not use setInterval/setTimeout for the clock; it slowly becomes incorrect.