2011-12-19 28 views
1
jid = Jabber::JID.new('[email protected]') 
    j = Jabber::Client.new(jid) 
    j.connect 
    j.auth('12345') 

,如果我試圖通過傳輸發送消息時,它響應了我XMPP4R ICQ傳輸煩惱

SENDING: 
<message to='[email protected]' xmlns='jabber:client'><body>hi!</body></message> 
=> nil 
ruby-1.9.2-p290 :106 > RECEIVED: 
<message from='[email protected]' to='[email protected]/38185266013242853702144' type='error'><error code='401' type='auth'><not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Error. You must log into the transport before sending messages.</text></error><body>hi!</body></message> 
PROCESSING: 
<message from='[email protected]' to='[email protected]/38185266013242853702144' type='error' xmlns='jabber:client'><error code='401' type='auth'><not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Error. You must log into the transport before sending messages.</text></error><body>hi!</body></message> (Jabber::Message) 

但:

iq = Jabber::Iq.new(:set) 

    query = Jabber::IqQuery.new 
    query.add_namespace('jabber:iq:auth') 
    query.add(REXML::Element.new('username').add_text("6...6")) 
    query.add(REXML::Element.new('password').add_text('F...1')) 

    iq.add(query) 
    iq.to = 'icq.proc.ru' 
    iq 

    j.send iq 


SENDING: 
<iq to='icq.proc.ru' type='set' xmlns='jabber:client'><query xmlns='jabber:iq:authenticate'><username>6....6</username><password>F....1</password></query></iq> 
=> nil 
ruby-1.9.2-p290 :105 > RECEIVED: 
<iq from='icq.proc.ru' to='[email protected]/38185266013242853702144' type='error'><error code='501' type='cancel'><feature-not-implemented/></error></iq> 
PROCESSING: 
<iq from='icq.proc.ru' to='[email protected]/38185266013242853702144' type='error' xmlns='jabber:client'><error code='501' type='cancel'><feature-not-implemented/></error></iq> (Jabber::Iq) 

我不能使用Iq.new_authset_digest(JID,SESSION_ID,密碼),因爲我不能得到session_id參數 我做錯了什麼?

回答

0
jid = Jabber::JID.new('user') 

    client = Jabber::Client.new(jid) 

    client.connect('54.187.67.96',5222) 
    client.auth('password') 
    client.send(Jabber::Presence.new.set_show(:chat).set_status('Rails!')) 
    puts "Hurray...!! Connected..!!" 


    # Send an Instant Message. 
    body = 'Hello from Rails' 
    to_jid = Jabber::JID.new('user') 
    message = Jabber::Message::new(to_jid, body).set_type(:normal).set_id('1') 
    client.send(message)