Socket.io with local client. Origin null and Access-Control-Allow-Origin

I'm trying to test a simple socket.io example with a local client. Here is my code:

server:

var sio = require('socket.io');
var io = sio.listen(8077, {log: false});

io.sockets.on('connection', function (socket) {
    console.log('connection detected');
    socket.on('hello', function(data){
        console.log('hello received: ' + data);
    });
});

client:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <script src="socket.io-client/dist/socket.io.js" type="text/javascript"></script>
  </head>
  <body>
    <script type="text/javascript">
      var socket = io.connect('http://localhost:8077');
      if(socket != undefined){
          socket.emit('hello', 'this is a test');
      }
    </script>
  </body>
</html>

If I put my client in a remote server, it runs perfectly, but if I try to run my client from local, my browser gives me the following error:

XMLHttpRequest cannot load http://localhost:8077/socket.io/1/?t=1343494806858.
Origin null is not allowed by Access-Control-Allow-Origin

I know that there is a http header which solves this problem in a http server, but I don't know if there is a similar option in sockets context. I need a local client. I don't want to serve the client code from an extra http nodejs server.

Have you tried setting the server origins parameter (it sets the header you mentioned)?:

var sio = require('socket.io');
var io = sio.listen(8077, {log: false, origins: '*:*'});

Also now your not accessing that server locally, have you made sure to update the line:

var socket = io.connect('http://localhost:8077');

to include the ip (or domain if you have one) of the remote server:

var socket = io.connect('http://XX.XX.XX.XX:8077');

Can you see what line returns the error in the console (you using chrome/ff with firebug?). In the if statement the socket variable will probably never by undefined. The the recommended way to use the connection is to wait for it to be ready by attaching a callback to the connect event, eg:

socket.on('connect', function () {  // <-instead of the if
    socket.emit('hello', 'this is a test');
}