title: broadcast client disconnect to a particular room
body: <p>I am following this excellent <a href="http://modernweb.com/2013/09/30/building-multiplayer-games-with-node-js-and-socket-io/" rel="nofollow">Tutorial</a> to make my first test game in node.js</p>
  
  <p>Everything is working perfectly. Even when I changed it from two player to three player, still worked fine. But unfortunately the tutorial did not cover the <code>disconnect event</code>. Every event on server is happening against some client action. e.g join game, answer click etc.</p>
  
  <p>But i am stuck at broadcasting to all clients in a room when one of the user looses his internet connection because he performs no action to do that. By some search i found something like following</p>
  
  <pre><code>// Listen for Socket.IO Connections. Once connected, start the game logic.
  io.sockets.on('connection', function (socket)
  {
      //console.log('client connected');
      initGame(io, socket);
      io.sockets.on('disconnect', function ()
      {
          socket.broadcast.emit('playerDisconnected', 'x has disconnected');
      });
  });
  </code></pre>
  
  <p>This is not working. And I cant understand how to know and how to tell users in a room that who has disccented. Please guide me what i can do more to make question clear.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>With the help of given answer I am able to broadcast a disconnect event to all clients connected to the server. But what can i do to emit only to the particular game clients mean <strong>from where i could get gameid/roomid in this event</strong>. I see something like game socket in my working code/ (following is it). but I tried simple <code>socket.emit('playerDisconnected', 'x has disconnected');</code> it does not work and <code>emit.broadcast</code> works but not as i need</p>
  
  <pre><code>function initGame(sio, socket)
  {
      io = sio;
      gameSocket = socket;
      gameSocket.emit('app_ev_connected', { message: "You are connected!" });
  
      gameSocket.on('serv_ev_playerJoinGame', playerJoinGame);
      gameSocket.on('serv_ev_getRooms',getRooms);    
  }
  </code></pre>