title: How to send a message to specific user with socket.io?
body: <p>How can I send messages only to users with specific IDs, which are specified by me?</p>
  
  <p>For example, I have a user with id=5 and I want send a message only to him, not to all the connected. How should this id be sent to server when he's connecting? Is it possible at all?</p>
  
  <p>Client</p>
  
  <pre><code>&lt;?php
  $id=5; // id to send to
  echo '
  &lt;div id="id"&gt;'.$id.'&lt;/div&gt;
  &lt;div id="messages"&gt;&lt;/div&gt;
  &lt;input type="text" id="type"&gt;
  &lt;div id="btn"&gt;Press&lt;/div&gt;
  ';
  ?&gt;
  
  &lt;script&gt;
  $(document).ready(function(){
  var id=$('#id').html();
  var socket=io.connect('http://localhost:8010');
  socket.on('connecting',function(){alert('Connecting');});
  socket.on('connect',function(){alert('Connected');});
  socket.on('message',function(data){message(data.text);});
  function message(text){$('#messages').append(text+'&lt;br&gt;');}
  $('#btn').click(function(){
      var text=$('#type').val();
      socket.emit("message",{text:text});
  });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Server</p>
  
  <pre><code>io.sockets.on('connection',function(client){
      client.on('message',function(message){
          try{
              client.emit('message',message);
              client.broadcast.emit('message', message);
          }catch(e){
              console.log(e);
              client.disconnect();
          }
      });
  });
  </code></pre>