endpoint = TCP4StreamClientEndpoint(reactor, '127.0.0.1', 1080)
d = endpoint.connect(factory)

def connected(protocol):
    return protocol.waitForWhatever()
Proper use of a client and Deferred with Twisted