title: Express - socket.io - session. Refer to user id as socket id
body: <p>I am using <a href="https://www.npmjs.com/package/express-socket.io-session" rel="nofollow noreferrer">express-socket.io-session</a>. I think I was able to setup the basic config by seeing the tutorials:</p>
  
  <pre><code>//BASIC CONFIG?
  
  var clients = [];
  
  var session = require("express-session")({
      secret: 'some key',
      resave: true,
      saveUninitialized: true
  });
  var sharedsession = require("express-socket.io-session");
  app.use(session);
  
  io.use(function(socket, next){
     next();
  });
  
  io.use(sharedsession(session, {
    autoSave:true
  })); 
  
  io.on('connection', function(socket) {
  
      console.log("CLIENT CONNECTED");
      var session = socket.handshake.session;
      clients.push(socket);
  
      socket.on('disconnect', function() {
         console.log("CLIENT DISCONNECTED");
      });
  
  });
  </code></pre>
  
  <p>What I want to be able to do now is to refer to a specific client socket not by the socket but by the session id that should be assigned to that socket. When a user logins this happens: </p>
  
  <pre><code>req.session.user_id = user_id; 
  //(user_id is equal to DB {0,1,2,3...} ids
  </code></pre>
  
  <p>I was able to send sockets to specific clients when I did this:</p>
  
  <pre><code>clients[0].emit("to_do",info); // I don't know who is client index 0 compared to the login reference...
  </code></pre>
  
  <p>I would like to be able to do this or similar:</p>
  
  <pre><code>user_id = 3; // which would have a socket assigned
  
  clients(user_id).emit("to_do",info);
  </code></pre>
  
  <p>That would mean each client would have a socket assigned to its previously assigned id. How could I do this so I could specify the socket by that id? I am not experienced at all with all of this so sorry for any big mistakes. Thanks</p>