2011-12-30 10 views
0

私はpyxmpp2を使って他のクライアントとチャットするデモを書いたが、クライアントが約5分間アイドル状態のときにサーバはクライアントと切断する。タイムアウトなので、5分でプレゼンスメッセージを送信することにしました。私に困惑しているのは、プレゼンテーションメッセージを送信するタイミングですか?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要求のピジン実装をチェックしてください。

これが正しい方向に向けることを願っています。

James

関連する問題