title: socket io - Emitting message to individual socket
body: <p>It started off as a lynda.com tutorial project</p>
  
  <p>I have tried and tried and <em>tried</em> to get this to work. I want to be able to send a message to a specific chat member (send a message to one socket).</p>
  
  <p>I looked at this, and I was <em>still</em> unable to get mine to work.
  <a href="https://stackoverflow.com/questions/6563885/socket-io-how-do-i-get-a-list-of-connected-sockets-clients">Socket.IO - how do I get a list of connected sockets/clients?</a></p>
  
  <p>I've cut out as much as I could that was not part of this question.</p>
  
  <p>First file:</p>
  
  <pre><code>var io = require('socket.io'), connect = require('connect'), chatter = require('./chatter.js');
  
  var app = connect().use(connect.static('public')).listen(process.env.PORT || 3000);
  var chatRoom = io.listen(app);
  
  chatter.setSockets(chatRoom.sockets);
  
  chatRoom.sockets.on("connection", function(socket){
   chatter.connectChatter({
    socket: socket,
    username: socket.id
   });
  });
  </code></pre>
  
  <p>Second file:</p>
  
  <pre><code>     var allSockets = null;
          var members = [];
  
          exports.setSockets = function(sockets){
           allSockets = sockets;
          }
  
          exports.connectChatter = function(config){
           var exists = false;
           var self;
           for(var i = 0; i &lt; members.length; i++){
            if(members[i].userName == config.username){
             exists = true;
             break;
            }
           }
           if(!exists){
            self = {userName:config.username};
            members.push(self);
           }
  
           config.socket.emit("welcome",{user:self});
           allSockets.emit("getUsers",{users:members});
  
          config.socket.on("chat", function(data){
  
      allSockets.emit("chat", {message:data.message}); //works just fine
               sockets[socket].emit("chat", {message:data.message}); //WILL NOT WORK
               sockets[0].emit("chat", {message:data.message}); //WILL NOT WORK
               socket[0].emit("chat", {message:data.message}); //WILL NOT WORK
               allSockets[socket].emit("chat", {message:data.message}); //WILL NOT WORK
               allSockets[0].emit("chat", {message:data.message}); //WILL NOT WORK
  
               allSockets.socket(0).emit('chat', {message:data.message}); //DOES NOTHING, BUT DOES NOT BREAK APP
  </code></pre>
  
  <p>Please help. I'm sure it's something stupid or silly. I'm pretty new to this. I just don't know what the syntax is. </p>