Rectangle 27 0

There is some problem in the Game.update in game.js, it seems to be calling itself recursively.

if (Game.players[0].update()) {
    //This seems to execute recursively.
    socket.emit('move player', {x: Game.players[0].getX(), y: Game.players[0].getY(), angle: Game.players[0].getAngle()});
    Game.background.update(Game.players[0].getX(), Game.players[0].getY());
}
count=0;
if (Game.players[0].update()) {
    socket.emit('move player', {x: Game.players[0].getX(), y: Game.players[0].getY(), angle: Game.players[0].getAngle()});
    count +=1;
    console.log(count);
    Game.background.update(Game.players[0].getX(), Game.players[0].getY());
}

I could not understand the logic by looking at the code and tell if it is right behaviour. But it keeps sending move player requests to server.

After some testing, I found that the issue is due to synchronization.

When a client loads the page, it starts emitting the move player right away, even before it connects to the server and runs onSocketConnected. The number of lines you get on the error console are equal to the number of messages sent before Connected to socket server is shown in console. Try the code I used for debugging.

So it is breaking the assumption that client shouldn't emit the "move player" until after the connection is established. Hope this helps you.

Thanks for your help! I added your debugging code to game.js and checked the console for the count, and noticed something strange. I went back to check the node console and the "(onMovePlayer) player not found:" message wasn't displayed at all! I was confused by this so I commented out your debugging code and restarted the client and noticed the same thing... The only thing I did was update node from 0.10.1 to 0.10.3 and then reinstalled socket.io. Is it possible that there was a bug in node or socket itself that was causing this synchronization error?

node.js - Socket.io firing callback function multiple times - Stack Ov...

node.js socket.io