title: socket.io data seems to be sent multiple times(nodejs and craftyjs)
body: <p>I am following <a href="http://buildnewgames.com/introduction-to-crafty/" rel="nofollow">this</a> tutorial on making HTML5 games. I wanted to try and mix node in to make it multiplayer. I am using node.js(v0.10.4) on server and crafty.js on front end.</p>
  
  <p>I am using socket.io to send and receive messages. For now it's just me(not multiple clients). The weird thing that happens is that the message that comes from the server seems to be sent multiple times. I turned on debug mode in socket.io but it only seems to be sending the data once, yet on the front end the data seems to be coming in, in multiples. I set an incrementor on the data and it seems as if the incrementor is not incrementing multiple times but instead I am getting multiple copies of the same data.</p>
  
  <p>here's node code: </p>
  
  <pre><code>var http = require('http').createServer(handler),
  static = require('node-static'),
  io = require('socket.io').listen(http);
  
  io.set('log level', 3);
  http.listen(80);
  //attach the socket to our server
  var file = new static.Server(); //Create a file object so we can server the files in the correct folder
  
  function handler(req, res) {
      req.addListener('end', function() {
        file.serve(req, res);
      }).resume();
  }
  
  io.sockets.on('connection', function (socket) { //listen for any sockets that will come from the client 
    socket.on('collected', function(data) {
     /**** here's where the data is being sent back to the client *****/
     socket.emit('messageFromServer', { data: data.number });
    });
  });
  </code></pre>
  
  <p>and here's front end code:</p>
  
  <pre><code>//messenger entity
  Crafty.c('SendRecieveMessages',{
      count: 0,
      sendMessageToServer : function() {
        console.log('got a village');
        /**** Here's where we send the message to the server ****/
        socket.emit('collected', { village : "The message went to the server and back. it's collected", number : this.count });
        this.count++;
  },
  recieveMessageFromServer : function() {
      socket.on('messageFromServer', function(data) {
          /*** This data seems to be coming back or logging multiple times? ***/  
          console.log(data);
      });
  }
  });
  </code></pre>
  
  <p>Lastly here's a screenshot of the debug in process. As you can see number is not always incrementing, it almost looks like the data is getting stored. Thanks!</p>
  
  <p><a href="http://cl.ly/image/0i3H0q2P1X0S" rel="nofollow">http://cl.ly/image/0i3H0q2P1X0S</a></p>