changeset 12:ef8060d365cb

whitespace ping to avoid disconnection (was disconnected after 6 min of inactivity with openfire)
author Goffi <goffi@goffi.org>
date Wed, 28 Oct 2009 00:39:29 +0100
parents 37153f3a3dc1
children bd9e9997d540
files sat.tac
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/sat.tac	Tue Oct 27 01:21:35 2009 +0100
+++ b/sat.tac	Wed Oct 28 00:39:29 2009 +0100
@@ -21,7 +21,7 @@
 
 
 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 @@
         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