XMPP transport to ICQ

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 07:04:55

问题


I try to send messages to icq via jabber-transport. I tried to use code from this answer XMPP transport to another protocol, but I got this message:

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>

Please explain me: What am I doing wrong? Thanks in advance.

Here's my code

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

Updated code:

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

returns:

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>

and still doesnt work


回答1:


You only need to register transport only first time, then you need to send initial presence after session creation.



来源:https://stackoverflow.com/questions/26975237/xmpp-transport-to-icq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!