2013-04-02 77 views
0

我試圖測試使用xmpp4r將消息發送到一個JID賬號:不能發送消息xmpp4r?

require 'xmpp4r' 
include Jabber 

jid = JID::new('[email protected]') 
password = 'secr3t' 

cl = Client::new(jid) 
cl.connect('166.78.7.179') 
cl.auth(password) 
cl.send(Presence.new) 

to = '[email protected]' 
subject = 'XMPP4R test' 
body = 'Hi, this is a XMPP4R test' 
m = Message::new(to, body).set_type(:chat).set_id('1').set_subject(subject) 
cl.send m 

但我總是得到以下異常:

/home/subout/.rvm/gems/[email protected]/gems/xmpp4r-0.5/lib/xmpp4r/client.rb:118:in `rescue in auth': closed stream (Jabber::ClientAuthenticationFailure) 
    from /home/subout/.rvm/gems/[email protected]/gems/xmpp4r-0.5/lib/xmpp4r/client.rb:108:in `auth' 
    from send_message2.rb:9:in `<main>' 

回答

1
  • 首先,請你在cl.connect之前添加Jabber::debug = true設置 並在此輸出?
  • 其次,它看起來像有一個與XMPP服務器有問題(你確定它運行在 「166.78.7.179」?)
  • 而且,最後但並非最不重要的,你爲什麼決定 使用「過時「xmpp4r而不是現代接班人 Blather
+0

當我從葡萄藤切換到ejabberd後,它工作正常。我也想嘗試Blather,但是如何發送簡單的消息而不用EventMachine阻塞? – Samnang

+0

葡萄藤有一些問題,是的。 Vines Agent代碼充滿了發送帶EM的非阻塞節的示例。 – mudasobwa

+0

@mudasobwa現在看看藤代理代碼,但如果你能指出這樣一個例子,我會很感激。 – gduq