【问题标题】:handle client disconnect with openfire server If the client is idle for 5mins处理客户端与 openfire 服务器断开连接如果客户端空闲 5 分钟
【发布时间】:2011-12-30 05:15:42
【问题描述】:

我用pyxmpp2写了一个和其他客户端聊天的demo,但是当客户端空闲5分钟左右服务器会与客户端断开连接,openfire无法配置超时,所以我决定在5分钟内发送一个在线消息,困扰我的问题是什么时候发送 presense 消息?

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()

但是好像不行……

【问题讨论】:

    标签: python xmpp openfire


    【解决方案1】:

    看看

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

    这详细说明了 OF 中的断开空闲属性,您可以将其设置为以毫秒为单位的值

    断开空闲客户端的连接在基于会话的通信中很重要。它更多地与客户端意外关闭有关,而不仅仅是需要空闲。

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

    希望这会引导您朝着正确的方向前进。

    詹姆斯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-17
      • 2013-03-31
      • 2023-03-30
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多