Shane_S
Shane_S

Reputation: 129

Using node.js and socket.io to broadcast every second

I am currently working on an auction script using node.js and socket.io. The site will have 500-1000 logged in users viewing a single page during the auction. Only one item will be on sale at any one time, similar to a real auction held in an auction house.

I will be broadcasting a countdown timer to all of the signed in users from the server to the client. On the server side I will be using setInterval() of 1 second to countdown to the auction end time. Apart from this the only other message being sent across will be the current bid being passed from a single client to the server then broadcast to all. Will this be a reliable way to do this? And will it be able to handle the usage on the server?

If not is there a way which would be better?

Thanks Shane

Upvotes: 3

Views: 1788

Answers (1)

Pranav
Pranav

Reputation: 2172

For timer value, keep updating your local timer per second on server side itself. Whenever any user comes in, give him this value and also total value of timer. Then client will start their own timers locally as per comment by dandavis, but keep some interval like 15 or 10 seconds on server side on which server will broadcast the current timer value so that client will sync accordingly.

In short, server will broadcast every after 10(n:you decide) seconds but it will be updating timer variable per second locally. Whenever client comes in, it will get total timer value and current timer value.

Rest functionality of broadcasting the current bid can be done in normal way.

Upvotes: 2

Related Questions