You can close the server in the server's connection function, it won't actually close until the last connection has gone away. Saves a few lines of code.