0

我有一些使用 XMPP4r 构建的机器人,我看到一个奇怪的问题,即它们在联机一段时间后会出现脱机。(没有固定的时间)

一个晚上我会在我的名单上看到他们,第二天早上我会在第二天早上醒来,发现他们出现在离线状态。我可以给他们发消息,他们回复很好,他们只是出现离线。

如果我重新启动它们,它们将立即再次出现在我的名单中。这发生在多个 XMPP 客户端(iChat、Adium、Meebo)和多个独立的机器人上,所以我不认为这是侥幸。

关于我应该从哪里开始寻找的任何建议?我正在运行我自己的 Prosody 服务器,所以我知道这不是重新启动。可能是静默重新连接问题吗?

4

1 回答 1

1

突然,我们名为 Bender 的友好 jabber bot 停止工作,我发现主要问题是服务器发送如下 ping:

<iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='s2c1' type='get'>
  <ping xmlns='urn:xmpp:ping'/>
</iq>

客户应该这样回应:

<iq from='juliet@capulet.lit/balcony' to='capulet.lit' id='s2c1' type='result'/>

更多信息请访问http://xmpp.org/extensions/xep-0199.html#s2c

我在尝试连接到 Mountain Lion Server 消息服务器时发生了这种情况(也许其他服务器有相同的要求)。

一位朋友找到了一个简单的方法来解决这个问题:

#!/usr/bin/env ruby
require 'rubygems'
require 'xmpp4r'
require 'xmpp4r/roster'
require 'xmpp4r/client'
require 'xmpp4r/muc'

Jabber::debug = true
client = Jabber::Client.new(Jabber::JID.new('user@macbook.local'))
client.connect
client.auth('password')
muc = Jabber::MUC::MUCClient.new(client)
muc.join(Jabber::JID::new('chatroom@conference.macbook.local' + client.jid.node))

# add the callback to respond to server ping
client.add_iq_callback do |iq_received|
  if iq_received.type == :get
    if iq_received.queryns.to_s != 'http://jabber.org/protocol/disco#info'
      iq = Jabber::Iq.new(:result, client.jid.node)
      iq.id = iq_received.id
      iq.from = iq_received.to
      iq.to = iq_received.from
      client.send(iq)
    end
  end
end

我希望这段代码可以帮助其他人。

问候爱德华多

于 2012-08-02T22:29:11.943 回答