title: Socket.io : How to handle/manage multiple clients requests and responses?
body: <p>I am very eager to integrate Socket.io to my node.js project, but I have some confusions on how to properly use socket.io. I have been looking through documentations and tutorials, but I have not been able to understand some concepts on how socket.io works. </p>
  
  <p>The scenario I have in mind is the following: </p>
  
  <ul>
  <li>There are multiple clients C1, C2, ..., Cn</li>
  <li>Clients emit request to the server R1,...,Rn</li>
  <li>Server receives request, does data processing</li>
  <li>When data-processing is complete, Server emits response to clients Rs1, .., Rs2</li>
  </ul>
  
  <p>The confusion I have in this scenario is that, when the server has finished data processing it emits the response in the following way:</p>
  
  <pre><code>// server listens for request from client
  socket.on('request_from_client', function(data){
      // user data and request_type is stored in the data variable
      var user = data.user.id
      var action = data.action
  
      // server does data processing 
      do_some_action(..., function(rData){
          // when the processing is completed, the response data is emitted as a response_event
          // The problem is here, how to make sure that the response data goes to the right client
          socket.emit('response_to_client', rData)
      })
  })
  </code></pre>
  
  <p>But here I have NOT defined which client I am sending the response to!</p>
  
  <ul>
  <li>How does socket.io handle this ? </li>
  <li>How does socket.io make sure that: response Rs1 is sent to C1 ?</li>
  <li>What is making sure that: response Rs1 is not sent to C2 ? </li>
  </ul>
  
  <p>I hope I have well explained my doubts. </p>