title: How to detect socket disconnection on client side?
body: <p>I am using <code>nodejs v0.11.0-pre</code> and <code>socket.io version 0.9.11</code> and I want to detect socket disconnection on client side. I am using this code to do alert on disconnect this but it seems that I am doing some thing wrong any one can help, thanks </p>
  
  <p>Client:</p>
  
  <pre><code>&lt;script src="http://127.0.0.1:4000/socket.io/socket.io.js"&gt;&lt;/script&gt;
  &lt;script src="http://code.jquery.com/jquery-1.7.1.min.js"&gt;&lt;/script&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
    var socket = io.connect('127.0.0.1',{port:4000});
    console.log("connected");  
    socket.on('disconnect', function () {
          alert('disconnected');
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Server: </p>
  
  <pre><code>var http = require('http');
  var app = http.createServer().listen(4000)
  ,io = require('socket.io').listen(app);
  io.sockets.on('connection', function (socket) {
      console.log("client has established :" + socket.id);
  socket.on('disconnect', function () {
      console.log("client has disconnected :" + socket.id);
  });       
  });
  </code></pre>
  
  <p>Every thing works fine on the server, but there is no alert on disconnect on client.</p>