title: how to know if a specific socket in open in socket.io?
body: <p>I am just starting with socket.io and node.js. I have some code for sending a message to a specific client:</p>
  
  <pre><code>io.sockets.sockets[receiverssocket2].emit('message',
  {"source": sendersusername,
  "message": msg.message,
  "target": msg.target});
  </code></pre>
  
  <p>I get the receivers socket id from a pgsql server. Sometimes it takes a bit long to update, so when a user disconnects receiverssocket2 still exists and a message is emitted to the particular socket id, which gives an error as the socket does not exist.
  Is there a way i can check if the socket id exists and then emit the message?
  I can get a list of connected sockets and check if it exists in the array, but that might take time.</p>