I'm far from an expert but I've been working on an HTML5 version of Pong that uses Websockets for multiplayer so I can share what's been working for me. The general maxim I've been living by is:
"Send the minimal amount of information necessary as infrequently as possible."
In my case I maintain the state of the keyboard by listening for the keyup
and keydown
events in the client. When one of these events is fired the client sends a message to the server and then updates its own state. This allows the client to employ client-side prediction (see this article for more details) and gives the server the minimal amount of information it needs to execute the move.
When the server receives one of these events it updates its own internal state and then rebroadcasts the event to all other clients so they can handle it as well.
To keep everything in sync the server will periodically (every 10 ticks of the engine in my case) send a "sync state" message to all of the clients giving them the exact positions of all players. You never want to sync the state of a client to the server as that opens up all sorts of cheating opportunities.
EDIT
To be clear, state syncing should only ever go from the server to the client, never the other way around.
END EDIT
I found Maple.js to be quite useful as a reference for a concrete implementation in Javascript.