【移动应用开发技术】asmack xmpp应用遇到的问题_第1页
【移动应用开发技术】asmack xmpp应用遇到的问题_第2页
【移动应用开发技术】asmack xmpp应用遇到的问题_第3页
【移动应用开发技术】asmack xmpp应用遇到的问题_第4页
【移动应用开发技术】asmack xmpp应用遇到的问题_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【移动应用开发技术】asmackxmpp应用遇到的问题

项目中遇到要用xmpp做通讯,原来在的应用跑在linux上用的gloox,现在需要在android上来实现,查了下发现smack最近做了一次大升级,4.0.0发布了,最开始用了smack的库,结果在android上报错,去/

社区问了下,原来还有个asmack,下了库文件然后写代码:根据asmack-android-8-4.0.0-rc2.jar

的readme,另外需要dnsjava的库,我用的是dnsjava-2.1.6最开始发现logcat有一个关于dns的报错,网上查了下发现有说要加下面一句在初始化的时候:

//System.setProperty("vider.1","dns,dnsjava");但是后来我发现没有这句,好像也没问题,暂时屏蔽掉了。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方式的设置,发现连接没问题,但是login的时候总是返回noresponseerror,查了发现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就认为是账户已经存在。由于服务器强制使用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社区的帖子/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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论