You need to
- subscribe to the
connectionevent of the server and add opened sockets to an array - keep track of the open sockets by subscribing to their
closeevent and removing the closed ones from your array - call
destroyon all of the remaining open sockets when you need to terminate the server
You also have the chance to run the server in a child process and exit that process when you need.