Python 如果客户端空闲5分钟,处理客户端与openfire server的断开连接

Python 如果客户端空闲5分钟,处理客户端与openfire server的断开连接,python,xmpp,openfire,Python,Xmpp,Openfire,我写了一个关于使用pyxmpp2与其他客户端聊天的演示,但是当客户端空闲约5分钟时,服务器将断开与客户端的连接,openfire无法配置超时,因此我决定在5分钟内发送状态消息,让我困惑的问题是何时发送prensense消息 import pyxmpp2 class EchoBot(EventHandler, XMPPFeatureHandler): """Echo Bot implementation.""" def __init__(self, my_jid, setting

我写了一个关于使用pyxmpp2与其他客户端聊天的演示,但是当客户端空闲约5分钟时,服务器将断开与客户端的连接,openfire无法配置超时,因此我决定在5分钟内发送状态消息,让我困惑的问题是何时发送prensense消息

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()
但它似乎不起作用…

请检查

这详细说明了dissconnect idle属性,您可以将其设置为以毫秒为单位的值

断开空闲客户端的连接在基于会话的通信中非常重要。这更多的是由于客户端意外关闭,而不仅仅是因为它处于空闲状态

如上所述,您可以在客户机中实现ping或心跳数据包发送。也许可以看看空白IQ请求的洋泾浜实现

希望这能引导你走向正确的方向

詹姆斯