开发者

Twisted connectionLost Event

开发者 https://www.devze.com 2022-12-21 13:49 出处:网络
I use the twisted.words.protocols.jabber.client.XMPPClientFactory . Do you know how I can callback a function whe开发者_运维百科n the connection gets lost (for example WiFi-connection is down)?

I use the twisted.words.protocols.jabber.client.XMPPClientFactory . Do you know how I can callback a function whe开发者_运维百科n the connection gets lost (for example WiFi-connection is down)?

thank you for your help!


You can either add a bootstrap for xmlstream.STREAM_END_EVENT or set a defer to clientConnectionLost.

from twisted.words.protocols.jabber import client
from twisted.words.protocols.jabber import jid
from twisted.words.protocols.jabber import xmlstream

j = jid.JID("name@example.org/bla")
p = "some pass"

factory = client.XMPPClientFactory(j, p)

bootstrap method

factory.addBootstrap(
    xmlstream.STREAM_END_EVENT,
    some_fuction,
)

or

defer method

d = defer.Deferred()
factory.clientConnectionLost = d
0

精彩评论

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