2011-12-30 127 views
0

我写了一个关于与其他客户端使用pyxmpp2聊天的演示,但是当客户端空闲大约5分钟时,服务器将与客户端断开连接,openfire无法配置超时,所以我决定在5分钟内发送一个在线消息,令我费解的问题是何时发送prensense消息?处理客户端与openfire服务器断开连接如果客户端空闲5分钟

import pyxmpp2 

class EchoBot(EventHandler, XMPPFeatureHandler): 
    """Echo Bot implementation.""" 
    def __init__(self, my_jid, settings): 
     version_provider = VersionProvider(settings) 
     self.client = Client(my_jid, [self, version_provider], settings) 
    @event_handler(AuthorizedEvent) 
    def handle_authorized(self,event): 
     presence = Presence(to_jid ="....",stanza_type = "available") 
     self.client.stream.send(presence) 
    def run(self): 
     """Request client connection and start the main loop.""" 
     self.client.connect() 
     self.client.run() 
    def disconnect(self): 
     """""" 
     self.client.disconnect() 
    def keepconnect(self): 
     presence = Presence(to_jid ="....",stanza_type = "available") 
     self.client.stream.send(presence) 
     print "send presence" 
.... 
bot = McloudBot(JID(mcloudbotJID), settings) 
try: 
     bot.run()   
     t = threading.Thread(target=bot.run()) 
     timer=threading.Timer(5,bot.keepconnect()) 
     t.start() 
     timer.start() 
except KeyboardInterrupt: 
     bot.disconnect() 

但似乎没有工作...

回答

0

退房

http://community.igniterealtime.org/docs/DOC-2053

这方面的细节在该dissconnect闲置的房屋,你可以设置为毫秒的

在基于会话的通信中,断开闲置客户端是非常重要的。它与客户意外关闭有关,而不仅仅是闲置。

如上所述,您可以在客户端中实施ping或心跳包发送。也许可以查看空白IQ请求的pidgin实现。

希望这可以帮助你朝正确的方向发展。

詹姆斯

相关问题