我有一个twisted tcp客户端,我想定期让它连接,接收n秒的数据流,然后断开连接。 断开连接后,在进程重新开始之前,将经过n秒。在
下面是我迄今为止尝试过的代码的一个非常简短的摘录。 当我运行代码时反应器.停止()发出,在睡眠结束后我得到一个扭曲的互联网当反应器.运行()在startClientConnection()中调用
我对使用twisted是个新手,我不知道我做错了什么。任何帮助都将不胜感激。在
class TCPClientFactory(ReconnectingClientFactory)
def startedConnecting(self, connector):
pass
def buildProtocol(self, addr):
self.resetDelay()
return MsgProcessor()
def clientConnectionLost(self, connector, reason):
ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
def clientConnectionFailed(self, connector, reason):
ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
class mainClass(object):
def __init__(self):
...
def startClientConnection(self):
reactor.connectTCP(host, port, TCPClientFactory())
reactor.callLater(60, self.periodic_connect_manager)
reactor.run()
def periodic_connect_manager(self):
reactor.stop()
time.sleep(60)
self.startClientConnection()
reactor.run()
只能运行一次。在相关问题 更多 >
编程相关推荐