3

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?

Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122
Pippi
  • 2,451
  • 8
  • 39
  • 59

1 Answers1

7

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.

Glyph
  • 31,152
  • 11
  • 87
  • 129