title: socket connection closed before receiving a handshake response
body: <p>I have written code for socket from :<a href="http://socket.io/docs/" rel="nofollow">source</a></p>
  
  <p>My code looks like this.</p>
  
  <pre><code>var port = 8081;
  var app = require('http').createServer();
  var io = require('socket.io')(app);
  app.listen(port);
  
  io.on('connection', function (socket) {
      console.log("New user connected.");
      socket.emit('news', { hello: 'world' });
      socket.on('my other event', function (data) {
          console.log(data);
      });
  });
  console.log("server listening on: " + port);
  </code></pre>
  
  <p>But when I am testing it on <a href="http://www.websocket.org/echo.html" rel="nofollow">here</a> (ws://localhost:8081). I am getting 
  ERROR: undefined 
  DISCONNECTED</p>
  
  <p>In console I am getting error:</p>
  
  <pre><code>WebSocket connection to 'ws://localhost:8081/?encoding=text' failed: Connection closed before receiving a handshake response
  </code></pre>