Pippi
Pippi

Reputation: 2571

Can reactor.connectTCP occur after reactor.run in twisted python?

I wish to add more protocols and factories after reactor runs. I couldn't find documentation which says this is allowed. When I make reactor.run before reactor.connectTCP, the program hangs around buildProtocol in factory. Is it possible to add reactor.connectTCP to the reactor after reactor.run?

Upvotes: 3

Views: 1107

Answers (1)

Glyph
Glyph

Reputation: 31860

Yes, you can start or stop listening on a TCP port at any time in Twisted. However, code like

reactor.run()
reactor.listenTCP(...)

won't work because run() only returns when the reactor has been stopped and the program is ready to exit. So you need to call listenTCP in response to something.

Also, don't use listenTCP directly; it's a very low-level API. Instead, use Endpoints.

Upvotes: 7

Related Questions