def METHOD_NAME(self):
    try:
        self.proxyServerFactory.protoInstance.transport.loseConnection()
    except AttributeError:
        pass
    try:
        pi = self.proxyServerFactory.clientFactoryInstance.protoInstance
        pi.transport.loseConnection()
    except AttributeError:
        pass
    try:
        self.clientProtocol.transport.loseConnection()
    except AttributeError:
        pass
    try:
        self.serverProtocol.transport.loseConnection()
    except AttributeError:
        pass
    return defer.gatherResults(
        [defer.maybeDeferred(p.stopListening) for p in self.openPorts]
    )