I\'m using NodeJS+Socket.IO for simple web game. It works. Why?
Here\'s my server.js
var app = require(\'express\').createServer();
var
Client-side. A player moves and the function movePlayer is executed:
function movePlayer () {
socket.emit ('player move', {map: 4, coords: '0.0'});
}
socket.on ('updatePlayer', function (msg) {
console.log ('A player moves on map ' + msg.map + ' on coords ' + msg.coords);
});
Server-side. When someone moves, a 'updatePlayer' is emitted for each socket except the original player. On each client side, the updatePlayer is intercepted.
socket.on ('player move', function (msg) {
io.sockets.emit ('updatePlayer', msg);
});
Server side
socket.on('updatePlayer', function(updatePlayer){
console.log("Someone just moved on the map!")
updatePlayer() // will trigger the client side function
});
Client side
socket.emit('updatePlayer', function(){
console.log('testing');
})