2013-04-02 109 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