title: Socket.io server doesn't seem to get a connection?
body: <p>I'm working my way through the tutorials on <a href="http://nodetuts.com/" rel="nofollow">NodeTuts</a>. I'm trying to get a chat server working using <a href="http://socket.io/" rel="nofollow">socket.io</a>.</p>
  
  <p>I can start the node instance fine and I get the "socket.io ready - accepting connections" message when I do. When I point my browser at localhost:8888 I get served the html form from template.html also so that all looks good. I never seem to make a socket connection though and I never see the "Connection Received" log or the 'Welcome to the chat server' message.</p>
  
  <p>Any ideas what the problem is?</p>
  
  <pre><code>var fs, http, io, server, socket, sys;
    http = require('http');
    fs = require('fs');
    sys = require('sys');
    io = require('socket.io');
    server = http.createServer(function(req, res) {
      var rs;
      console.log('server started');
      res.writeHead(200, {
        'Content-Type': 'text/html'
      });
      rs = fs.createReadStream(__dirname + '/template.html');
      return sys.pump(rs, res);
    });
    socket = io.listen(server);
    socket.on('connection', function(client) {
      var username;
      console.log('Connection received');
      client.send('Welcome to the chat server');
      client.send('Please enter a username');
      return client.on('message', function(message) {
        if (!username) {
          username = message;
          return client.send("Hi " + username + "!");
        } else {
          return socket.broadcast("" + username + ": " + message);
        }
      });
    });
    server.listen(8888);
  </code></pre>
  
  <p>Here's the JS part of template.html</p>
  
  <pre><code>&lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      $(function() {
        socket = new io.Socket('localhost', {port: 8888});
        socket.on('message', function(message) {
          var data = message.data
          data = data.replace(/&amp;/g, "&amp;amp;").replace(/&lt;/g, "&amp;lt;").replace(/&gt;/g, "&amp;gt;");
          console.log( data );
          $('#log ul').append('&lt;li&gt;' + data + '&lt;/li&gt;');
          window.scrollBy(0, 1000000000000000);
          entry_el.focus();
        });
  
  
        var entry_el = $('#entry');
        entry_el.keypress(function(event) {
          if (event.keyCode != 13) return;
          var msg = entry_el.attr('value');
          // if the message is not empty
          if (msg) {
              socket.send(msg);
              entry_el.attr('value', '');
          }
        });
      });
    &lt;/script&gt;
  </code></pre>