'When the underlying connection is closed, stop the running service (if
any), and log out the avatar (if any).
@type reason: L{twisted.python.failure.Failure}
@param reason: The cause of the connection being closed.'

def connectionLost(self, reason):

    if self.service:
        self.service.serviceStopped()
    if hasattr(self, 'avatar'):
        self.logoutFunction()
    log.msg('connection    lost')
