Roy*_*yHB 2 twisted twisted.internet twisted.client
当使用 Twisted ReconnectingClientFactory 并且连接丢失时,我是否需要从 clientConnectionLost 方法中调用 connector.connect() 还是会自动发生?
答案似乎很明显,因为它毕竟是 ReconnectingClientFactory但 Twisted 文档在这里说了一些让我想知道的东西:
“调用 connector.connect() 可能很有用 - 这将重新连接。”
术语“可能有用”的措辞和使用导致了这个问题,因为基本客户端工厂的 api 文档也说了同样的事情。
Max 的答案是正确的,但经过进一步研究,我认为“更正者”的答案如下:
def clientConnectionLost(self, connector, reason):
# do stuff here that is unique to your own requirements, then:
ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
Run Code Online (Sandbox Code Playgroud)
这允许您执行应用程序所需的专门操作,然后调用工厂代码以允许 Twisted 为您调用 retry()。
我的旧答案并不完全正确。而是这样做:
Run Code Online (Sandbox Code Playgroud)def clientConnectionLost(self, connector, reason): # do stuff here that is unique to your own requirements, then: ReconnectingClientFactory.clientConnectionLost(self, connector, reason)这允许您执行应用程序所需的专门操作,然后调用工厂代码以允许 Twisted 为您调用 retry()。
| 归档时间: |
|
| 查看次数: |
2052 次 |
| 最近记录: |