I finally got socket.io to work properly, but I have encountered a strange problem.
I am not sure if this is the best way, but I am using:
io.sockets.cli
I am currently using Socket.io v1.3.6 and have found that this works. It gives an accurate number when users connect and when they disconnect:
io.sockets.sockets.length
Like so:
var io = require('socket.io').listen(server);
io.on('connection', function(socket) {
console.log(io.sockets.sockets.length);
socket.on('disconnect', function() {
console.log(io.sockets.sockets.length);
});
});