views:

123

answers:

1

Hey there, I use the twisted.words.protocols.jabber.client.XMPPClientFactory . Do you know how I can callback a function when the connection gets lost (for example WiFi-connection is down)?

thank you for your help!

A: 

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("[email protected]/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
Silas