comparison sat.tac @ 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 5799493fa548
children bd9e9997d540
comparison
equal deleted inserted replaced
11:37153f3a3dc1 12:ef8060d365cb
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 22
23 from twisted.application import internet, service 23 from twisted.application import internet, service
24 from twisted.internet import glib2reactor, protocol 24 from twisted.internet import glib2reactor, protocol, task
25 glib2reactor.install() 25 glib2reactor.install()
26 26
27 from twisted.words.protocols.jabber import client, jid, xmlstream, error 27 from twisted.words.protocols.jabber import client, jid, xmlstream, error
28 from twisted.words.xish import domish 28 from twisted.words.xish import domish
29 29
153 # add a callback for the messages 153 # add a callback for the messages
154 xmlstream.addObserver('/message', self.gotMessage) 154 xmlstream.addObserver('/message', self.gotMessage)
155 xmlstream.addObserver('/presence', self.presenceCb) 155 xmlstream.addObserver('/presence', self.presenceCb)
156 xmlstream.addObserver("/iq[@type='set' or @type='get']", self.iqCb) 156 xmlstream.addObserver("/iq[@type='set' or @type='get']", self.iqCb)
157 print "********** CONNECTED **********" 157 print "********** CONNECTED **********"
158 self.connected=True 158 self.connected=True
159 self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") #Needed to avoid disconnection (specially with openfire)
160 self.keep_alife.start(180)
161
159 #reactor.callLater(2,self.sendFile,"goffi2@jabber.goffi.int/Psi", "/tmp/fakefile") 162 #reactor.callLater(2,self.sendFile,"goffi2@jabber.goffi.int/Psi", "/tmp/fakefile")
160 163
161 def connectionLost(self, connector, unused_reason): 164 def connectionLost(self, connector, unused_reason):
162 print "********** DISCONNECTED **********" 165 print "********** DISCONNECTED **********"
166 if self.keep_alife:
167 self.keep_alife.stop()
163 self.connected=False 168 self.connected=False
164 169
165 170
166 def sendMessage(self,to,msg,type='chat'): 171 def sendMessage(self,to,msg,type='chat'):
167 #FIXME: check validity of recipient 172 #FIXME: check validity of recipient