如果客户端空闲5分钟,请处理客户端与openfire服务器的断开连接

2024-06-07 18:57:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我写了一个用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()

但似乎没用。。。在


Tags: runselfclientsend消息客户端settingsmy
1条回答
网友
1楼 · 发布于 2024-06-07 18:57:28

退房

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

这将详细说明中的disconnect idle属性,您可以将其设置为毫秒数

在基于会话的通信中,分离空闲客户端是很重要的。这与客户机意外关闭有关,而不仅仅是空闲。在

如上所述,您可以在客户机中实现ping或心跳数据包发送。也许可以看看whitespaceiq请求的pidgin实现。在

希望这能指引你正确的方向。在

詹姆斯

相关问题 更多 >

    热门问题