突然,我们名为 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
我希望这段代码可以帮助其他人。
问候爱德华多