For the client in the form of webpage, press F5 to refresh, and the server catches the Disconnect event:

socket.on('disconnect'.function(){ 
    log.info("disconnect");
    eventEmitter.emit('close',socket);
  });
Copy the code

In the context of the event handler, the socket structure gets the following information:

_events: The events listened on the socket and the corresponding handler.

Connected: disconnected – Socket connection state bit

With this socket ID, the server can do the corresponding destructor to release the resources corresponding to the connection.

For more of Jerry’s original articles, please follow the public account “Wang Zixi “: