title: How to emit event in socket.io based on client?
body: <p>I am working on realtime data visualization application using <code>node.js, express and socket.io</code>. </p>
  
  <h3>Requirement:</h3>
  
  <p>Have to emit the events based on the client request.</p>
  
  <p><strong>For example</strong>: If user enter the url as <code>http://localhost:8080/pages</code> socket.io should emit the topic <code>pages</code> to client and another user request for <code>http://localhost:8080/locations</code> socket should emit <code>location</code> to that particular user.</p>
  
  <h3>Code</h3>
  
  <pre><code>    var server = app.listen("8080");
      var socket = require('socket.io');
      var io = socket.listen(server);
      var config = {};
      io.on('connection', function (socket) {
            config.socket = io.sockets.socket(socket.id);
            socket.on('disconnect', function () {
               console.log('socket.io is disconnected');
            });
      });
  
  
  
      app.get('/*', function(req, res) {
        var url = req.url;
        var eventName = url.substring('/'.length);
         //pages and locations
        config.socket.volatile.emit(eventName, result);
      });
  </code></pre>
  
  <p>Client Code:</p>
  
  <pre><code>          //No problem in client code.Its working correctly. 
              Sample code as follows
            socket.on('pages', function (result) {
                 console.log(result);
            }); 
  </code></pre>
  
  <h3>Problem:</h3>
  
  <p>It is emitting <code>pages</code> and <code>locations</code> to both the clients. </p>
  
  <p>Any suggestion to overcome this problem.</p>