title: Using disconnect function on socket.io and node.js
body: <p>I am trying to have it so when a user disconnects from my chat room, it pops up with " has left chat room". </p>
  
  <p>Here is my server code:</p>
  
  <pre><code>var app = require('express')();
  var http = require('http').Server(app);
  var io = require('socket.io')(http);
  
  app.get('/', function(req, res){
    res.sendfile('chat/index.html');
  });
  
  
  
  
  io.on('connection', function(socket){
    socket.on('chat message', function(msg){
      io.emit('chat message', msg);
    });
  
    socket.on('disconnect', function(nickname){
     io.emit('disconnect', nickname);
    });
  
  });
  
  http.listen(3000, function(){
    console.log('listening on *:3000');
  });
  </code></pre>
  
  <p>And here is my client code:</p>
  
  <pre><code>var socket = io();
    var nickname;
    var leaving;
  
    $('messageForm').submit(function(){
      socket.emit('chat message', (nickname + ": " + $('#m').val()));
      $('#m').val('');
      return false;
    });
  
    $('#nicknameForm').submit(function(){
  
     nickname = $('#nickname').val();
  
     if(nickname ==''){
    alert("Please enter a value");
    }else{
     $( "#dialog" ).dialog( "close" );
     leaving = nickname + " has left";
      }
      return false;
    });
  
    socket.on('chat message', function(msg){
      $('#messages').append($('&lt;li&gt;').text(msg));
    });
  
  
     socket.on('disconnect', function(nickname){
      socket.emit('disconnect message', nickname);
    });
  </code></pre>
  
  <p>At the moment, nothing appears at all, and I'm not too sure why.</p>