【问题标题】:Can reactor.connectTCP occur after reactor.run in twisted python?在 twisted python 中 reactor.run 之后会发生 reactor.connectTCP 吗?
【发布时间】:2015-11-07 22:53:38
【问题描述】:

我希望在反应堆运行后添加更多协议和工厂。我找不到说明这是允许的文档。当我在reactor.connectTCP 之前制作reactor.run 时,该程序在工厂中围绕buildProtocol 挂起。是否可以在reactor.run之后将reactor.connectTCP添加到reactor中?

【问题讨论】:

    标签: python twisted twisted.internet


    【解决方案1】:

    是的,您可以在 Twisted 中随时启动或停止侦听 TCP 端口。但是,像

    这样的代码
    reactor.run()
    reactor.listenTCP(...)
    

    不会工作,因为run() 仅在反应器停止并且程序准备退出时返回。所以你需要打电话给listenTCP来回应一些事情。

    另外,不要直接使用listenTCP;这是一个非常低级的 API。请改用Endpoints

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多