title: Sending messages client->server->client on socket.io on node.js
body: <p>I'm using NodeJS+Socket.IO for simple web game. It works. Why?</p>
  
  <p>Here's my <code>server.js</code></p>
  
  <pre><code>var app = require('express').createServer();
  var io = require('socket.io').listen(app);
  
  io.sockets.on('connection', function (socket) {
  socket.on('set nickname' , function (nickname) {
  socket.nickname = nickname;
  console.log(nickname + ' just connected!');
  
  });
  
  socket.on('msg' , function (msg) {
  socket.msg = msg;
  io.sockets.emit('response', msg);
  });
  
  socket.on('updatePlayer' , function (updatePlayer) {
  console.log("Someone just moved on the map!");
  });
  
  });
  
  app.listen(8080);
  </code></pre>
  
  <p>The reason I know it works is because, when I load the page and this script executes:</p>
  
  <pre><code>// SERVER STUFF
  socket.on('connect', function () {
      console.log('We are connected!');
      name = $(".name").val();
      this.emit('set nickname', name, function (success) {});
      msg = name + "|" + currX + "|" + currY + "|" + currentMap;
      this.emit('msg', msg, function (success) {});
  
      socket.on('response', function (data) {
          var theMsg = data.split("|");
          sayDialog("New player! " + theMsg[0] + " connected on map " + theMsg[3] + " on coordinates (" + theMsg[1] + "," + theMsg[2] + ")");
      });
  });
  </code></pre>
  
  <p>I get in my dialogbox ("CSS div") something like <code>New player! weka connected on map 4 on coordinates (10,5)</code></p>
  
  <p>OK, cool, so it works! However, when I "move" I try sending a message to server using this</p>
  
  <pre><code>  socket.on('updatePlayer', function () {
      console.log("Testing...");
    }); 
  </code></pre>
  
  <p>I don't even see <code>console</code> say Testing. I don't know why.</p>