title: Socket.io disconnection event triggers after long
body: <p>I am just trying to create a simple app using Socket.io. I am trying to send a notification (technically, emit an event) to all the connected users, if a particular user, User X, has disconnected, that User X has left or has disconnected.
  Here is my server side code.</p>
  
  <pre><code>io.on('connection', function(socket){
  console.log('Connected! ' + socket.id);
  
  socket.on('disconnect', function(){
    for(var i=0;i&lt;onlineUsers.length;i++)
    {
      if(onlineUsers[i].socketId == socket.id)
      {
          var newMessage = {};
          newMessage.socketId = onlineUsers[i].socketId;
          newMessage.fullName = onlineUsers[i].fullName;
          newMessage.message = newMessage.fullName + " IS DISCONNETED!";
          io.emit('newMessage', newMessage);
  
          onlineUsers.splice(i,1);
          console.log('splicing id ' + socket.id);
      }
    }
  }
  </code></pre>
  
  <p>I guess that the code is executing but takes long to emit the disconnection event. I receive the disconnection message about 2 minutes after the client had disconnected. Why does it take so long? What might be the wrong in this code?</p>
  
  <p>I also cannot understand when exactly the client is considered as disconnected. If the app closes, or the browser closes or the internet goes down?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Update: I have a test deployment on Cloud9 and my live deployment is on Azure Cloud. I have realized that Cloud9 works just perfect, this seems like an issue with Azure.</strong></p>
  
  <p><strong>Update 2: Whenever I disconnect/close/refresh my web client, I immediately get the disconnected event emitted by the server. The same does not happen for my mobile client. Why?</strong></p>