2013-02-18 110 views
2

我試圖連接到使用的紅寶石我xmpp4r XMPP服務器和我的代碼很簡單,但我不知道爲什麼我有錯誤。 我能成功使用iChat登錄使用聊天@本地,也對5280 /管理網站。xmpp4r拋出異常的登錄:「捕獲到異常解析器線程(Jabber的:: ServerDisconnected)」

require 'xmpp4r/client' 
include Jabber 
Jabber::debug = true 
jid = Jabber::JID.new('[email protected]') 
client = Jabber::Client.new(jid) 
client.connect 
client.auth('123456') 
client.close 

和錯誤是:

D, [2013-02-18T03:24:55.768029 #15238] DEBUG -- : Debugging mode enabled. 
W, [2013-02-18T03:24:55.768341 #15238] WARN -- : Warnings mode enabled. 
D, [2013-02-18T03:24:55.772467 #15238] DEBUG -- : RESOLVING: 
_xmpp-client._tcp.localhost (SRV) 
D, [2013-02-18T03:24:55.778631 #15238] DEBUG -- : CONNECTING: 
localhost:5222 
D, [2013-02-18T03:24:55.780122 #15238] DEBUG -- : SENDING: 
<stream:stream xmlns:stream='http://etherx.jabber.org/streams'  
xmlns='jabber:client' to='localhost' xml:lang='en' version='1.0' > 
D, [2013-02-18T03:24:55.782276 #15238] DEBUG -- : RECEIVED: 
<stream:stream from='localhost' id='3021975152' xml:lang='en' 
xmlns:stream='http://etherx.jabber.org/streams' version='1.0'  
xmlns='jabber:client'/> 
D, [2013-02-18T03:24:55.784022 #15238] DEBUG -- : RECEIVED: 
<stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>  
<mechanism>SCRAM-SHA-1</mechanism><mechanism>DIGEST-MD5</mechanism> 
<mechanism>PLAIN</mechanism></mechanisms><c hash='sha-1' 
node='http://www.process-one.net/en/ejabberd/' 
ver='yy7di5kE0syuCXOQTXNBTclpNTo=' xmlns='http://jabber.org/protocol/caps'/> 
<register xmlns='http://jabber.org/features/iq-register'/></stream:features> 
D, [2013-02-18T03:24:55.784203 #15238] DEBUG -- : FEATURES: waiting... 
D, [2013-02-18T03:24:55.784785 #15238] DEBUG -- : FEATURES: received 
D, [2013-02-18T03:24:55.785290 #15238] DEBUG -- : PROCESSING: 
<stream:features xmlns='jabber:client'><mechanisms 
xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>SCRAM-SHA-1</mechanism>  
<mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism></mechanisms><c 
hash='sha-1' node='http://www.process-one.net/en/ejabberd/' 
ver='yy7di5kE0syuCXOQTXNBTclpNTo=' xmlns='http://jabber.org/protocol/caps'/> 
<register xmlns='http://jabber.org/features/iq-register'/></stream:features> 
(REXML::Element) 
D, [2013-02-18T03:24:55.785360 #15238] DEBUG -- : FEATURES: waiting finished 
D, [2013-02-18T03:24:55.785450 #15238] DEBUG -- : TRYING stanzacbs... 
D, [2013-02-18T03:24:55.785556 #15238] DEBUG -- : TRYING 
message/iq/presence/cbs...  
D, [2013-02-18T03:24:55.785987 #15238] DEBUG -- : SENDING: 
<auth mechanism='DIGEST-MD5' xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/> 
D, [2013-02-18T03:24:55.787784 #15238] DEBUG -- : RECEIVED: 
<challenge xmlns='urn:ietf:params:xml:ns:xmppsasl'>bm9uY2U9IjE5NzEzNzk5NzQiLHFvcD0iYXV0aCIsY2hhcnNldD11dGYtOCxhbGdvcml0aG09bWQ1LXNlc3M=</challenge> 
D, [2013-02-18T03:24:55.788143 #15238] DEBUG -- : SASL DIGEST-MD5 challenge: 
nonce="1971379974",qop="auth",charset=utf-8,algorithm=md5-sess 
{"nonce"=>"1971379974", "qop"=>"auth", "charset"=>"utf-8", "algorithm"=>"md5-sess"} 
D, [2013-02-18T03:24:55.788475 #15238] DEBUG -- : SASL DIGEST-MD5 response: 
nonce="1971379974",charset=utf-8,username="chat",realm="localhost",cnonce="92a37c018b9c32339c4b52ee0b02d67e",nc=00000001,qop=auth,digest-uri="xmpp/localhost",response=9c6bca9f4cf6f8daf3197a914023729a 
{"nonce"=>"\"1971379974\"", "charset"=>"utf-8", "username"=>"\"chat\"", "realm"=>"\"localhost\"", "cnonce"=>"\"92a37c018b9c32339c4b52ee0b02d67e\"", "nc"=>"00000001", "qop"=>"auth", "digest-uri"=>"\"xmpp/localhost\"", "response"=>"9c6bca9f4cf6f8daf3197a914023729a"} 
D, [2013-02-18T03:24:55.788761 #15238] DEBUG -- : SENDING: 
<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>bm9uY2U9IjE5NzEzNzk5NzQiLGNoYXJzZXQ9dXRmLTgsdXNlcm5hbWU9ImNoYXQiLHJlYWxtPSJsb2NhbGhvc3QiLGNub25jZT0iOTJhMzdjMDE4YjljMzIzMzljNGI1MmVlMGIwMmQ2N2UiLG5jPTAwMDAwMD 
    AxLHFvcD1hdXRoLGRpZ2VzdC11cmk9InhtcHAvbG9jYWxob3N0IixyZXNwb25zZT05YzZiY2E5ZjRjZjZm 
OGRhZjMxOTdhOTE0MDIzNzI5YQ==</response> 
D, [2013-02-18T03:24:55.818548 #15238] DEBUG -- : RECEIVED: 
<challenge xmlns='urn:ietf:params:xml:ns:xmpp-  
sasl'>cnNwYXV0aD01NTQ2NTVlYjljYWUzZGExMjhmZjBkMWUzNDUzYmIwZQ==</challenge> 
D, [2013-02-18T03:24:55.819064 #15238] DEBUG -- : SENDING: 
<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/> 
D, [2013-02-18T03:24:56.147820 #15238] DEBUG -- : RECEIVED: 
<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/> 
D, [2013-02-18T03:24:56.148432 #15238] DEBUG -- : SENDING: 
<stream:stream xmlns:stream='http://etherx.jabber.org/streams' 
xmlns='jabber:client' to='localhost' xml:lang='en' version='1.0' > 
D, [2013-02-18T03:25:56.151018 #15238] DEBUG -- : SENDING: 

W, [2013-02-18T03:25:56.212617 #15238] WARN -- : EXCEPTION: 
Jabber::ServerDisconnected 
Server Disconnected! 
/home/ubuntu/.rvm/gems/ruby-1.9.3-p385/gems/xmpp4r- 
0.5/lib/xmpp4r/streamparser.rb:68:in `block in parse' 
/home/ubuntu/.rvm/rubies/ruby-1.9.3- 
p385/lib/ruby/1.9.1/rexml/parsers/sax2parser.rb:195:in `call' 
/home/ubuntu/.rvm/rubies/ruby-1.9.3- 
p385/lib/ruby/1.9.1/rexml/parsers/sax2parser.rb:195:in `block in handle' 
/home/ubuntu/.rvm/rubies/ruby-1.9.3- 
p385/lib/ruby/1.9.1/rexml/parsers/sax2parser.rb:195:in `each' 
/home/ubuntu/.rvm/rubies/ruby-1.9.3- 
p385/lib/ruby/1.9.1/rexml/parsers/sax2parser.rb:195:in `handle' 
/home/ubuntu/.rvm/rubies/ruby-1.9.3- 
p385/lib/ruby/1.9.1/rexml/parsers/sax2parser.rb:95:in `parse' 
/home/ubuntu/.rvm/gems/ruby-1.9.3-p385/gems/xmpp4r-  
0.5/lib/xmpp4r/streamparser.rb:79:in `parse' 
/home/ubuntu/.rvm/gems/ruby-1.9.3-p385/gems/xmpp4r- 
0.5/lib/xmpp4r/stream.rb:75:in `block in start' 
W, [2013-02-18T03:25:56.212740 #15238] WARN -- : Exception caught in Parser 
thread! (Jabber::ServerDisconnected) 
/home/ubuntu/.rvm/gems/ruby-1.9.3-p385/gems/xmpp4r-  
0.5/lib/xmpp4r/streamparser.rb:68:in `block in parse' 

任何想法?

謝謝!

回答

0

使用Jabber在Facebook上發送消息時,我也面臨這個問題。

即使包裝在try/catch語句,有時,Jabber::ServerDisconnected拋出,造成Web服務器停止。 在xmpp4r源代碼,當在每個線程

https://github.com/lnussbaum/xmpp4r/blob/master/lib/xmpp4r/streamparser.rb價和https://github.com/lnussbaum/xmpp4r/blob/master/lib/xmpp4r/stream.rb

我想在例外的孤兒螺紋拋出接收斷開信號和Thread.abort_on_exception = true它們拋出Jabber::ServerDisconnected。 我沒有解決方案,但該設置Thread::abort_on_exception = false全局(在使用Jabber類/方法)一種解決方法。所以異常仍然拋出,但我們忽略它。

0

有錯誤處理的更好的方法,如docs提到:

If you want your connection to survive disconnects and timeouts, catch exception in Stream#on_exception and re-call Client#connect and Client#auth. Don‘t forget to re-send initial Presence and everything else you need to setup your session.

Stream#on_exception link