【移動應用開發(fā)技術】asmack xmpp應用遇到的問題_第1頁
【移動應用開發(fā)技術】asmack xmpp應用遇到的問題_第2頁
【移動應用開發(fā)技術】asmack xmpp應用遇到的問題_第3頁
【移動應用開發(fā)技術】asmack xmpp應用遇到的問題_第4頁
【移動應用開發(fā)技術】asmack xmpp應用遇到的問題_第5頁
已閱讀5頁,還剩10頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

【移動應用開發(fā)技術】asmackxmpp應用遇到的問題

項目中遇到要用xmpp做通訊,原來在的應用跑在linux上用的gloox,現(xiàn)在需要在android上來實現(xiàn),查了下發(fā)現(xiàn)smack最近做了一次大升級,4.0.0發(fā)布了,最開始用了smack的庫,結果在android上報錯,去/

社區(qū)問了下,原來還有個asmack,下了庫文件然后寫代碼:根據(jù)asmack-android-8-4.0.0-rc2.jar

的readme,另外需要dnsjava的庫,我用的是dnsjava-2.1.6最開始發(fā)現(xiàn)logcat有一個關于dns的報錯,網(wǎng)上查了下發(fā)現(xiàn)有說要加下面一句在初始化的時候:

//System.setProperty("vider.1","dns,dnsjava");但是后來我發(fā)現(xiàn)沒有這句,好像也沒問題,暫時屏蔽掉了。asmack的初始化是必須的。

mSmackAndroid=SmackAndroid.init(context);

conf=newConnectionConfiguration("",5222);

SASLAuthentication.supportSASLMechanism("PLAIN",0);

conf.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

conf.setCompressionEnabled(false);

//disablethebuilt-inReconnectionManagersincewehandlethis

conf.setReconnectionAllowed(false);

conf.setSendPresence(false);

conf.setDebuggerEnabled(true);

XMPPConnection

connection=XMPPTCPConnection(conf);

connection.login(g_email,g_password);最開始少了sasl方式的設置,發(fā)現(xiàn)連接沒問題,但是login的時候總是返回noresponseerror,查了發(fā)現(xiàn)asmask對于連接出錯拋的異常比較簡單,不會細分。log如下:connect:06-1709:39:09.300

19344-19457/com.wooxclound.homedaemonactivity.appD/SMACK﹕SENT(0):<stream:streamto=""xmlns="jabber:client"xmlns:stream="/streams"version="1.0">06-1709:39:12.500

19344-19458/com.wooxclound.homedaemonactivity.appD/SMACK﹕RCV(0):<?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream='/streams'id='1920830504'from=''version='1.0'xml:lang='en'><stream:features><starttlsxmlns='urn:ietf:params:xml:ns:xmpp-tls'/><mechanismsxmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>SCRAM-SHA-1</mechanism></mechanisms><cxmlns='/protocol/caps'hash='sha-1'node='/en/ejabberd/'ver='k0acyvEdZQ7cl5uD5FTPoiOnuaw='/><registerxmlns='/features/iq-register'/></stream:features>login:06-1709:39:21.500

19344-19457/com.wooxclound.homedaemonactivity.appD/SMACK﹕SENT(0):<authmechanism="PLAIN"xmlns="urn:ietf:params:xml:ns:xmpp-sasl">AHRlc3QxMUB3b294b25saW5lLmNvbQBhYjEyMzR5eg==</auth>06-1709:39:21.500

19344-19344/com.wooxclound.homedaemonactivity.appI/WooxHomeDaemon﹕onStartCommand():Intentcom.wooxclound.homedaemon.action.XMPP.CONNECTION_CHANGED06-1709:39:22.090

19344-19458/com.wooxclound.homedaemonactivity.appD/SMACK﹕RCV(0):<successxmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>06-1709:39:22.100

19344-19458/com.wooxclound.homedaemonactivity.appD/SMACK﹕SENT(0):<stream:streamto=""xmlns="jabber:client"xmlns:stream="/streams"version="1.0">06-1709:39:22.490

19344-19458/com.wooxclound.homedaemonactivity.appD/SMACK﹕RCV(0):<?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream='/streams'id='2952941696'from=''version='1.0'xml:lang='en'><stream:features><bindxmlns='urn:ietf:params:xml:ns:xmpp-bind'/><sessionxmlns='urn:ietf:params:xml:ns:xmpp-session'/><cxmlns='/protocol/caps'hash='sha-1'node='/en/ejabberd/'ver='k0acyvEdZQ7cl5uD5FTPoiOnuaw='/><registerxmlns='/features/iq-register'/></stream:features>06-1709:39:22.540

19344-19346/com.wooxclound.homedaemonactivity.appD/dalvikvm﹕GC_CONCURRENTfreed311K,8%free5028K/5408K,paused4ms+3ms,total26ms06-1709:39:22.560

19344-19457/com.wooxclound.homedaemonactivity.appD/SMACK﹕SENT(0):<iqid='Aa7TB-0'type='set'><bindxmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>Smack</resource></bind></iq>06-1709:39:23.130

19344-19458/com.wooxclound.homedaemonactivity.appD/SMACK﹕RCV(0):<iqid='Aa7TB-0'type='result'><bindxmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid>test11@/Smack</jid></bind></iq>06-1709:39:23.130

19344-19457/com.wooxclound.homedaemonactivity.appD/SMACK﹕SENT(0):<iqid='Aa7TB-1'type='set'><sessionxmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>06-1709:39:23.720

19344-19458/com.wooxclound.homedaemonactivity.appD/SMACK﹕RCV(0):<iqtype='result'id='Aa7TB-1'/>06-1709:39:23.730

19344-19454/com.wooxclound.homedaemonactivity.appD/SMACK﹕Userlogged(0):test11@@:0/Smack在注冊新用戶的時候,可以使用accountmanager也可以使用IQpackage,方法如下:

publicstaticfinalintREGISTER_METHOD_ACCOUNT_MANAGER=0;

publicstaticfinalintREGISTER_METHOD_IQ_PACKAGE=1;

publicstaticfinalintREGISTER_RESULT_SERVER_NO_RESULT=0;

publicstaticfinalintREGISTER_RESULT_SUCCESS=1;

publicstaticfinalintREGISTER_RESULT_ACCOUNT_EXIST=2;

publicstaticfinalintREGISTER_RESULT_FAIL=4;

publicstaticfinalintREGISTER_RESULT_NO_CONNECTION=4;/**

*register

*

*@paramusername

*@parampassword

*@return1:success0:servernotreturn2:accountexist3:fail4:noconnection

*/

publicintregister(Stringusername,Stringpassword){

if(!((mConnection!=null)&&mConnection.isConnected())){

returnREGISTER_RESULT_NO_CONNECTION;

}else{

reg_method=REGISTER_METHOD_ACCOUNT_MANAGER;

Map<String,String>attributes=newHashMap<String,String>();

attributes.put("username",username);

attributes.put("password",password);

//attributes.put("email","");

//attributes.put("name","");

if(reg_method==REGISTER_METHOD_ACCOUNT_MANAGER){

try{

if(mAccountManager==null){

mAccountManager=AccountManager.getInstance(mConnection);

}

mAccountManager.createAccount(username,password,attributes);

}catch(Exceptionex){

L.e(TAG,ex);

if(ex.toString().equalsIgnoreCase("conflict")){

L.i(XmppManager.class,"accountexist!");

returnREGISTER_RESULT_ACCOUNT_EXIST;

}else{

L.i(XmppManager.class,"registerfail");

returnREGISTER_RESULT_FAIL;

}

}

L.i(XmppManager.class,"registersuccess!");

returnREGISTER_RESULT_SUCCESS;

}elseif(reg_method==REGISTER_METHOD_IQ_PACKAGE){

try{

Registrationreg=newRegistration();

reg.setType(IQ.Type.SET);

reg.setTo(mConnection.getServiceName());

reg.setAttributes(attributes);

PacketFilterfilter=newAndFilter(newPacketIDFilter(reg.getPacketID()),

newPacketTypeFilter(IQ.class));

PacketCollectorcollector=mConnection.createPacketCollector(filter);

mConnection.sendPacket(reg);

IQresult=(IQ)collector.nextResult(SmackConfiguration.getDefaultPacketReplyTimeout());

collector.cancel();

//System.out.println(result);

if(result==null){

L.i(XmppManager.class,"novaluereturnbyserver!");

returnREGISTER_RESULT_SERVER_NO_RESULT;

}elseif(result.getType()==IQ.Type.ERROR){

//<errorcode="409"type="cancel"><conflictxmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error>

if(result.getError().toString().equalsIgnoreCase("conflict")){

L.i(XmppManager.class,"accountexist!");

returnREGISTER_RESULT_ACCOUNT_EXIST;

}else{

L.i(XmppManager.class,"registerfail");

returnREGISTER_RESULT_FAIL;

}

}elseif(result.getType()==IQ.Type.RESULT){

L.i(XmppManager.class,"registersuccess!");

//Intentintent=newIntent(DaemonService.ACTION_REGISTER);

returnREGISTER_RESULT_SUCCESS;

}

L.e(TAG,":Shouldnotgothereforregisterprocess!");

}catch(Exceptionex){

L.e(TAG,ex);

}

}

L.e(TAG,":Shouldnotgothereforregisterprocess!");

returnREGISTER_RESULT_FAIL;

}

}}當賬戶存在時,返回如下包:D/SMACK﹕RCV(0):<iqtype="error"id="EzQN5-0"from=""to="/c220b282"><queryxmlns="jabber:iq:register"><email></email><password>jacky</password><username>jacky</username><name></name></query><errorcode="409"type="cancel"><conflictxmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>但是geterrorcode()接口似乎在4.0的asmack中被去掉了,所以只能判定error是conflict就認為是賬戶已經(jīng)存在。由于服務器強制使用TLS認證,所以對于連接做了新的配置,然后再openfireserver上測試沒有問題,但是在公司的服務器出問題了,最先我用的是asmak4.0.0rc2的庫,在認證challenge的時候服務器似乎沒有響應,log如下:D/SMACK﹕SENT(0):<stream:streamto=""xmlns="jabber:client"xmlns:stream="/streams"version="1.0">D/SMACK﹕RCV(0):<?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream='/streams'id='2936112787'from=''version='1.0'xml:lang='en'><stream:features><starttlsxmlns='urn:ietf:params:xml:ns:xmpp-tls'/><mechanismsxmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>SCRAM-SHA-1</mechanism></mechanisms><cxmlns='/protocol/caps'hash='sha-1'node='/en/ejabberd/'ver='k0acyvEdZQ7cl5uD5FTPoiOnuaw='/><registerxmlns='/features/iq-register'/></stream:features>D/SMACK﹕SENT(0):<starttlsxmlns="urn:ietf:params:xml:ns:xmpp-tls"/>D/SMACK﹕RCV(0):<proceedxmlns='urn:ietf:params:xml:ns:xmpp-tls'/>W/System.err﹕atorg.jivesoftware.smack.tcp.XMPPTCPConnection.initReaderAndWriter(XMPPTCPConnection.java:501)W/System.err﹕atorg.jivesoftware.smack.tcp.XMPPTCPCceedTLSReceived(XMPPTCPConnection.java:648)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader.parsePackets(PacketReader.java:223)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader.access$000(PacketReader.java:48)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader$1.run(PacketReader.java:82)W/System.err﹕atorg.jivesoftware.smack.tcp.XMPPTCPConnection.initReaderAndWriter(XMPPTCPConnection.java:501)W/System.err﹕atorg.jivesoftware.smack.tcp.XMPPTCPCceedTLSReceived(XMPPTCPConnection.java:648)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader.parsePackets(PacketReader.java:223)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader.access$000(PacketReader.java:48)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader$1.run(PacketReader.java:82)D/SMACK﹕SENT(0):<stream:streamto=""xmlns="jabber:client"xmlns:stream="/streams"version="1.0">D/SMACK﹕RCV(0):<?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream='/streams'id='3044304500'from=''version='1.0'xml:lang='en'>D/SMACK﹕RCV(0):<stream:features><mechanismsxmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>SCRAM-SHA-1</mechanism></mechanisms><cxmlns='/protocol/caps'hash='sha-1'node='/en/ejabberd/'ver='k0acyvEdZQ7cl5uD5FTPoiOnuaw='/><registerxmlns='/features/iq-register'/></stream:features>D/SMACK﹕SENT(0):<authmechanism="DIGEST-MD5"xmlns="urn:ietf:params:xml:ns:xmpp-sasl"></auth>D/SMACK﹕RCV(0):<challengexmlns='urn:ietf:params:xml:ns:xmpp-sasl'>bm9uY2U9IjIyNzI1NzYwOTQiLHFvcD0iYXV0aCIsY2hhcnNldD11dGYtOCxhbGdvcml0aG09bWQ1LXNlc3M=</challenge>D/SMACK﹕SENT(0):</stream:stream>W/XMPPConnection﹕Connectionclosedwitherror

java.lang.NullPointerException

atcom.novell.sasl.client.DigestMD5SaslClient.DigestCalcHA1(DigestMD5SaslClient.java:447)

atcom.novell.sasl.client.DigestMD5SaslClient.createDigestResponse(DigestMD5SaslClient.java:646)

atcom.novell.sasl.client.DigestMD5SaslClient.evaluateChallenge(DigestMD5SaslClient.java:356)

atorg.jivesoftware.smack.sasl.SASLMechanism.challengeReceived(SASLMechanism.java:190)

atorg.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:427)

atorg.jivesoftware.smack.tcp.PacketReader.parsePackets(PacketReader.java:252)

atorg.jivesoftware.smack.tcp.PacketReader.access$000(PacketReader.java:48)

atorg.jivesoftware.smack.tcp.PacketReader$1.run(PacketReader.java:82)翻了一下asmack社區(qū)的帖子/message/240015#240015上說rc3的庫解決了這個問題,down下來一試,果然,但是認證還是通不過:D/SMACK﹕SENT(0):<stream:streamto=""xmlns="jabber:client"xmlns:stream="/streams"version="1.0">D/SMACK﹕RCV(0):<?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream='/streams'id='83599252'from=''version='1.0'xml:lang='en'><stream:features><starttlsxmlns='urn:ietf:params:xml:ns:xmpp-tls'/><mechanismsxmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>SCRAM-SHA-1</mechanism></mechanisms><cxmlns='/protocol/caps'hash='sha-1'node='/en/ejabberd/'ver='k0acyvEdZQ7cl5uD5FTPoiOnuaw='/><registerxmlns='/features/iq-register'/></stream:features>D/SMACK﹕SENT(0):<starttlsxmlns="urn:ietf:params:xml:ns:xmpp-tls"/>D/SMACK﹕RCV(0):<proceedxmlns='urn:ietf:params:xml:ns:xmpp-tls'/>W/System.err﹕atorg.jivesoftware.smack.tcp.XMPPTCPConnection.initReaderAndWriter(XMPPTCPConnection.java:501)W/System.err﹕atorg.jivesoftware.smack.tcp.XMPPTCPCceedTLSReceived(XMPPTCPConnection.java:648)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader.parsePackets(PacketReader.java:223)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader.access$000(PacketReader.java:48)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader$1.run(PacketReader.java:82)W/System.err﹕atorg.jivesoftware.smack.tcp.XMPPTCPConnection.initReaderAndWriter(XMPPTCPConnection.java:501)W/System.err﹕atorg.jivesoftware.smack.tcp.XMPPTCPCceedTLSReceived(XMPPTCPConnection.java:648)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader.parsePackets(PacketReader.java:223)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader.access$000(PacketReader.java:48)W/System.err﹕atorg.jivesoftware.smack.tcp.PacketReader$1.run(PacketReader.java:82)D/SMACK﹕SENT(0):<stream:streamto=""xmlns="jabber:client"xmlns:stream="/streams"version="1.0">D/SMACK﹕RCV(0):<?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream='/streams'id='1654478887'from=''version='1.0'xml:lang='en'>D/SMACK﹕RCV(0):<stream:features><mechanismsxmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>SCRAM-SHA-1</mechanism></mechanisms><cxmlns='/protocol/caps'hash='sha-1'node='/en/ejabberd/'ver='k0acyvEdZQ7cl5uD5FTPoiOnuaw='/><registerxmlns='/features/iq-register'/></stream:features>D/SMACK﹕SENT(0):<authmechanism="DIGEST-MD5"xmlns="urn:ietf:params:xml:ns:xmpp-sasl"></auth>D/SMACK﹕RCV(0):<challengexmlns='urn:ietf:params:xml:ns:xmpp-sasl'>bm9uY2U9IjI4MDgzODM5MDUiLHFvcD0iYXV0aCIsY2hhcnNldD11dGYtOCxhbGdvcml0aG09bWQ1LXNlc3M=</challenge>D/SMACK﹕SENT(0):<responsexmlns="urn:ietf:params:xml:ns:xmpp-sasl">dXNlcm5hbWU9InRlc3QxMkB3b294b25saW5lLmNvbSIsY25vbmNlPSIwNWUxNjVlMjUxZDA2MzM3MzJmZWZjNzBjMDU4ZTkwMDU4YjM0MjE0Mjg4ZDlmNzM1NTAwMDVkOTc4NWIwNmFlIixuYz0wMDAwMDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL3dvb3hvbmxpbmUuY29tIixyZXNwb25zZT05YThiMzkxZjNjM2Q0MzdjOTc0MDNkYzJiNzkyNGU5MixjaGFyc2V0PXV0Zi04LG5vbmNlPSIyODA4MzgzOTA1Ig==</response>D/SMACK﹕RCV(0):<failurexmlns='urn:ietf:params:xml:ns:xmpp-sasl'><not-authorized/></failure>D/SMACK﹕SENT(1):<stream:streamto=""xmlns="jabber:client"xmlns:stream="/streams"version="1.0">D/SMACK﹕RCV(1):<?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream='/streams'id='3726488975'from=''version='1.0'xml:lang='en'><stream:features><starttlsxmlns='urn:ietf:params:xml:ns:xmpp-tls'/><mechanismsxmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>SCRAM-SHA-1</mechanism></mechanisms><cxmlns='/protocol/caps'hash='sha-1'node='/en/ejabberd/'ver='k0acyvEdZQ7cl5uD5FTPoiOnuaw='/><registerxmlns='/features/iq-register'/></stream:features>D/SMACK﹕SENT(1):<starttlsxmlns="urn:ietf:params:xml:ns:xmpp-tls"/>D/SMACK﹕RCV(1):<proceedxmlns='urn:ietf:params:xml:ns:xmpp-tls'/>D/SMACK﹕SENT(1):<stream:streamto=""xmlns="jabber:client"xmlns:stream="/streams"version="1.0">D/SMACK﹕RCV(1):<?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream='/streams'id='4109710539'from=''version='1.0'xml:lang='en'>D/SMACK﹕RCV(1):<stream:features><mechanismsxmlns

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論