0

我尝试通过 jabber-transport 向 icq 发送消息。我尝试使用此答案 XMPP transport to another protocol中的代码,但收到此消息:

DEBUG -- : SENDING:
    <message to='12345@icq.jabber.blahblah.ru' xmlns='jabber:client'><body>test
 message from robot</body></message>
=> nil
DEBUG -- : RECEIVED:
    <message from='12345@icq.jabber.blahblah.ru' to='myjit@blahblah.ru/83076
14161416233482839674' type='error'><error code='401' type='auth'><not-authorized
 xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:n
s:xmpp-stanzas'>Error. You must log into the transport before sending messages.<
/text></error><body>test message from robot</body></message>

请解释一下:我做错了什么?提前致谢。

这是我的代码

require 'rubygems'
require 'xmpp4r/client'
include Jabber

Jabber.debug = true
jid = JID::new('myjit@blahblah.ru')
pass = 'pwd'
server = 'jabber.blahblah.ru'
port = '5223'
subj = 'Nagios notification'
user = '12345@icq.jabber.blahblah.ru'
text = 'AAAA AAAA AAAA'
cl = Jabber::Client::new(jid)
cl.use_ssl = true
cl.connect(server,port)
cl.auth(pass) 

#connect to transport
reg=Jabber::Iq.new_register "54321", "pwd2"
reg.to="icq.jabber.blahblah.ru"
cl.send reg

mes = Message::new(user,text)
cl.send(mes)
cl.close()

更新代码:

cl.connect(server,port)
cl.auth(pass)

# sending initial presence
p = Jabber::Presence.new
cl.send p

mes = Message::new(user,text)
mes.type = :chat

cl.send(mes)
cl.close()

返回:

D, [2014-11-18T19:01:35.986182 #8084] DEBUG -- : SENDING:
    <presence xmlns='jabber:client'/>
=> nil
irb(main):027:0> D, [2014-11-18T19:01:36.048980 #8084] DEBUG -- : RECEIVED:
    <presence from='icq.jabber.blahblah.ru' to='myjit@blahblah.ru' type='subscri
be'><status/></presence>

仍然无法正常工作

4

1 回答 1

0

您只需要第一次注册传输,然后您需要在会话创建后发送初始状态。

于 2014-11-18T09:45:08.637 回答