title: socket.io not emitting event from server to client on connection
body: <p>I have a very basic setup with socket.io but am having trouble getting my server to send back a message once the connection has been established.</p>
  
  <p>When a connection is established to my server, I want the server to send back a message to the client. I've tried to accomplish this with the following code:</p>
  
  <p><strong>Server</strong></p>
  
  <pre><code>// Modules
  var fs = require('fs');
  var https = require('https');
  
  // Certificate
  var options = {
      pfx: fs.readFileSync('&lt;my cert&gt;')
  };
  
  
  // Create Server
  httpsServer = https.createServer(options);
  
  // Create websocket
  var io = require('socket.io')(httpsServer);
  
  // Listen on a port
  httpsServer.listen(4000,function() {
      console.log('listening on *:4000');
  });
  
  io.on('connection', function(socket) {
      console.log('a user connected');
      socket.emit('test','you connected');
  });
  </code></pre>
  
  <p><strong>Client</strong></p>
  
  <pre><code>var socket = io('https://&lt;my server&gt;:4000');
  </code></pre>
  
  <p>When I execute this code, the websocket gets established and my server console shows the message <code>"a user connected"</code>. However, the message <code>['test','you connected']</code> does not get emitted through the socket.</p>
  
  <p>The only way I've been able to get this to work is to use <code>setTimeout()</code> to wait 500ms before emitting the event, in which case it does work.</p>
  
  <p>Why is that? How can I configure my server to automatically respond with a message as soon as the user connects?</p>