Close listening socket before stopping running connections

If sending the serverStopped event to currently active connections
happens before actually closing the server socket, new connections will
be accepted in between, which in turn will stay open and prevent the
HTTP server from stopping completely.