XMPP transport to ICQ

450 views Asked by At

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='[email protected]' xmlns='jabber:client'><body>test
 message from robot</body></message>
=> nil
DEBUG -- : RECEIVED:
    <message from='[email protected]' to='[email protected]/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('[email protected]')
pass = 'pwd'
server = 'jabber.blahblah.ru'
port = '5223'
subj = 'Nagios notification'
user = '[email protected]'
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='[email protected]' type='subscri
be'><status/></presence>

and still doesnt work

1

There are 1 answers

1
vitalyster On

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