Using event emitter to handle asynchronously writing of response and closing of connection.