From 10b195a3453b59302f9ab96525dc32999afde3c3 Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 28 Oct 2009 00:39:29 +0100 Subject: [PATCH] whitespace ping to avoid disconnection (was disconnected after 6 min of inactivity with openfire) --- sat.tac | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sat.tac b/sat.tac index 0bb71248..2164534f 100644 --- a/sat.tac +++ b/sat.tac @@ -21,7 +21,7 @@ along with this program. If not, see . from twisted.application import internet, service -from twisted.internet import glib2reactor, protocol +from twisted.internet import glib2reactor, protocol, task glib2reactor.install() from twisted.words.protocols.jabber import client, jid, xmlstream, error @@ -155,11 +155,16 @@ class SAT: xmlstream.addObserver('/presence', self.presenceCb) xmlstream.addObserver("/iq[@type='set' or @type='get']", self.iqCb) print "********** CONNECTED **********" - self.connected=True + self.connected=True + self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") #Needed to avoid disconnection (specially with openfire) + self.keep_alife.start(180) + #reactor.callLater(2,self.sendFile,"goffi2@jabber.goffi.int/Psi", "/tmp/fakefile") def connectionLost(self, connector, unused_reason): print "********** DISCONNECTED **********" + if self.keep_alife: + self.keep_alife.stop() self.connected=False