Close listening socket before stopping running connections

Proposed fix for issue #436

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.