突然、Bender という名前のフレンドリーな jabber ボットが機能しなくなりました。主な問題は、サーバーが次のような 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
このコードが他の人に役立つことを願っています。
こんにちはエドゥアルド