title: SocketIO + Flask Detect Disconnect
body: <p>I had a different question here, but realized it simplifies to this:
  How do you detect when a client disconnects (closes their page or clicks a link) from a page (in other words, the socket connection closes)? I want to make a chat app with an updating user list, and I’m using Flask on Python. When the user connects, the browser sends a <code>socket.emit()</code> with an event and username passed in order to tell the server a new user exists, after which the server will message all clients with <code>socket.emit()</code>, so that all clients will append this new user to their user list. However, I want the clients to also send a message containing their username to the server on Disconnect. I couldn’t figure out how to get the triggers right. Note: I’m just using a simple html file with script tags for the page, I’m not sure how to add a JS file to go along with the page, though I can figure it out if it’s necessary for this.</p>