title: Socket.io server emits not firing
body: <p>Ok trying my hand at NodeJS and socket.io and have run into a problem.  I have NodeJS and Socket.io installed and running on my localhost.  At present I have the following setup:</p>
  
  <p><strong>server.js</strong></p>
  
  <pre><code>// Require HTTP module (to start server) and Socket.IO
  var http = require('http'), io = require('socket.io');
  
  // Start the server at port 8080
  var server = http.createServer(function(req, res){ 
  
  // Send HTML headers and message
    res.writeHead(200,{ 'Content-Type': 'text/html' }); 
    res.end('&lt;h1&gt;NodeJS Server Online&lt;/h1&gt;');
  });
  server.listen(8080);
  
  // Create a Socket.IO instance, passing it our server
  var socketserver = io.listen(server);
  
  // Add a connect listener
  socketserver.on('connection', function(socket){ 
  
      socket.emit("server ready");
  
      socket.on('test', function (msg) {
          socket.broadcast.emit('TEST:', msg);
          console.log(msg);
      });
  
      socket.on('user message', function (msg) {
          socket.broadcast.emit('user message', msg);
          console.log(msg);
      });
  
  });
  </code></pre>
  
  <p><strong>client.js</strong></p>
  
  <pre><code>$(document).ready(function() {
  // Stuff to do as soon as the DOM is ready;
      var socket =  io.connect('http://localhost',{port:8080});
  
      socket.on('server ready',function() {
          messages.append("&lt;li&gt;Server Ready...&lt;/li&gt;");
          console.log("Server Ready");
      });
  
      // Add a connect listener
      socket.on('connect',function() {
          messages.append("&lt;li&gt;Connected...&lt;/li&gt;");
          console.log("connected");
          socket.emit('test',"Just testing");
      });
  
  });
  </code></pre>
  
  <p>Server starts fine, but my problem is that the server.js does not fire the <strong>socket.emit("server ready");</strong> line.  The client side code works fine as in terminal.app on testing my server outputs this line:</p>
  
  <pre><code>websocket received data packet 5:::{"name":"test","args":["Just testing"]}
  </code></pre>
  
  <p>What am I missing? Why isn't the server side stuff firing?</p>