[Twisted-Python] How can a tcp client connect with multi servers?

Andrew Bennetts andrew-twisted at puzzling.org
Thu Dec 1 04:59:35 EST 2005

On Thu, Dec 01, 2005 at 05:48:12PM +0800, Xu Ryan wrote:
> I meet another problem. After i create some ClientCreate instance and
> let the reactor run , it works ok.
> But how could I send message when reactor is running? Because there
> are not only one services that twisted provide. And when I need send
> the messages i have told above , perhaps there are other service
> running , using the same reactor(becaus it's global), and obviously I
> can't stop it , re-create ClientCreator, then call reactor.run() to
> send the message.

You seem to misunderstand how to do concurrent operations in Twisted.  You don't
need to stop the reactor.  If at some point in your code you want to make
another connection with ClientCreator, just call ClientCreator's connectTCP
method as usual -- without stopping the reactor.  The point of the reactor is
that it takes care of managing multiple connections and the like at once.

So, it's not "stop [the reactor] , re-create ClientCreator, then call
reactor.run() to send the message", it's just "re-create ClientCreator".  It may
even be just "call connectTCP on your existing ClientCreator again."


More information about the Twisted-Python mailing list