Hi I am trying to build a realtime multiplayer game using node.js and socket.io.
Now, implementing itself in terms of coding won't be so much of a problem, but coming from a traditional http request-response web programming model, I have no idea how expensive this would be in terms of traffic and server load. Basically during a game, a player's browser should track realtime mouse input events and keep broadcasting them to all other players in the same game.
Here's an example, let's say my avatar follows around my mouse pointer on the screen, and it should be broadcasted to rest of the players on the screen in realtime. I would do something like:
// client side
$(document).on("mousemove", function(event){
io.emit("coordinate", {x: event.pageX, y: event.pageY});
});
and on the server:
// server side
io.sockets.on("connection", function(socket){
...
socket.on("coordinate", function(coordinate){
socket.get("username", function(err, username){
socket.broadcast.emit("move", {username: username, coordinate:coordinate});
});
});
...
});
I think this should work, but this requires the browser emitting several events per second to the server, which subsequently should broadcast them to rest of the players in the same game, and I am worried about the implication of this. One thing though is that the size of each fragment of data being transmitted is not that large (basically it's just an x and y coordinate). If this is too expensive, no matter how great this game is, I don't think I can ship it. Could anyone enlighten me? Thank you.
[EDIT] To clarify, I am not asking about how to make this architecture more efficient. I just want to know if this type of system is realistic enough in terms of system load (and maintenance cost) For ordinary web services I can just estimate the cost by looking at page view numbers but websocket is an entirely new field I am not aware of, so I wanted to ask.