开发者

stop ReconnectingClientFactory (XmlStreamFactory)

I tried to write a XMPP Client using this mentioned factories. Now my program only needs this connection during a short time. How can I make the 开发者_StackOverflowFactory to stop reconnection attempts? Unfortunately stopTrying doesn't work. Do I have to disconnect running connections before?

Any help would be appreciated :)


ReconnectingClientFactory.stopTrying does work. Any time you have a question like this, you shouldn't just say "doesn't work". You should explain your expectations, give a minimal example of the code you're trying, and explain how its behavior differs from your expectations.

For this case, here's an example which demonstrates how stopTrying meets my expectations, which are that after it is called, no further attempts will be made to establish the connection:

from twisted.internet.protocol import ReconnectingClientFactory
from twisted.internet import reactor
from twisted.python.log import startLogging
from sys import stdout

def main():
    startLogging(stdout)
    f = ReconnectingClientFactory()
    reactor.callLater(10, f.stopTrying)
    reactor.connectTCP('localhost', 12345, f)
    reactor.run()

if __name__ == '__main__':
    main()

This will run forever, but for the first 10 seconds of its run, it will be making new connection attempts (which all fail). After stopTrying is called, it will stop making such attempts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜