title: socket.io: disconnect event isn't fired
body: <p>I have made a simple realtime visitor counter.</p>
  
  <p>You can download it from <a href="https://bitbucket.org/bitliner/nodejs-mycounter">this repository</a>.</p>
  
  <p>What happens is that disconnect event (even after browser closing) on server is never fired.  </p>
  
  <p>server.js is:</p>
  
  <pre><code>(function () {
  var app, count, express, io;
  
  express = require('express');
  io = require('socket.io');
  
  app = module.exports = express.createServer();
  
  app.configure(function () {
      app.set('views', __dirname + '/views');
      app.set('view engine', 'jade');
      app.use(express.bodyParser());
      app.use(express.methodOverride());
      app.use(require('stylus').middleware({
          src: __dirname + '/public'
      }));
      app.use(app.router);
      return app.use(express.static(__dirname + '/public'));
  });
  
  app.configure('development', function () {
      return app.use(express.errorHandler({
          dumpExceptions: true,
          showStack: true
      }));
  });
  app.configure('production', function () {
      return app.use(express.errorHandler());
  });
  
  io = require('socket.io').listen(app);
  
  count = 0;
  
  io.sockets.on('connection', function (socket) {
      count++;
      io.sockets.emit('count', {
          number: count
      });
  });
  
  io.sockets.on('disconnect', function () {
      console.log('DISCONNESSO!!! ');
      count--;
      io.sockets.emit('count', {
          number: count
      });
  });
  
  
  app.get('/', function (req, res) {
      return res.render('index', {
          title: 'node.js express socket.io counter'
      });
  });
  if (!module.parent) {
      app.listen(10927);
      console.log("Express server listening on port %d", app.address().port);
  }
  
  }).call(this);
  </code></pre>
  
  <p>Script on the client is:</p>
  
  <pre><code>    script(type='text/javascript')
  
          var socket = io.connect();
  
          socket.on('count', function (data) {
              $('#count').html( data.number );
          });
  </code></pre>