Can’t connect to node.js server on client side

I’m having a problem getting started with Node.js.

I’ve created a basic server that I know works, because if I navigate to http://localhost:5000 in my browser I get the expected message. However, I’m having trouble then connecting to this server on the client side with a basic HTML page.

My Node.js app looks like this:

var http = require('http');
var socket = require('socket.io');

var port = process.env.PORT || 5000;

var players;

var app = http.createServer(function(request, response) {
    response.write('Server listening to port: ' + port);
    response.end();
}).listen(port);

var io = socket.listen(app);

function init() {    
    io.configure(function() { 
        io.set('transports', [ 'xhr-polling' ]); 
        io.set('polling duration', 10); 
    });
    io.sockets.on('connection', onSocketConnection);
};

function onSocketConnection(client) {
    console.log('New connection');
    console.log(client);
};

init();

My HTML page looks like this (based on https://github.com/mongolab/tractorpush-server/blob/master/index.html):

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <script src="/socket.io/socket.io.js"></script>
    <script>
        var socket = io.connect('/');

        socket.on('all', function(data) {
            console.log(data);
        });
        socket.on('complex', function(data) {
            console.log(data);
        });
    </script>
  </body>
</html>

I understand that the sockets.io.js file is automatically generated by socket.io, but I just get the following error when I view my index.html file:

Uncaught ReferenceError: io is not defined

How do I actually connect to my server?