XMPP 连接的 asmack-android-8-4.0.6.jar 问题
Posted
技术标签:
【中文标题】XMPP 连接的 asmack-android-8-4.0.6.jar 问题【英文标题】:asmack-android-8-4.0.6.jar issue for XMPP connection 【发布时间】:2014-12-02 07:43:00 【问题描述】:我使用 asmack-android-8-4.0.6.jar 作为 xmpp 的库,我能够连接到早期版本的 asmack lib,但是有了这个新的最新库,我遇到了异常,请帮帮我如何使用最新的 asmack 库启用 SSL 身份验证, 我没有找到 connConfig.setSASLAuthenticationEnabled(true);最新库中的方法
ConnectionConfiguration connConfig = new ConnectionConfiguration(HOST,PORT);
//connConfig.setSASLAuthenticationEnabled(true);
// connConfig.setCompressionEnabled(true);
connConfig.setSecurityMode(SecurityMode.enabled);
connConfig.setDebuggerEnabled(true);
connConfig.setSocketFactory(new DummySSLSocketFactory());
connection = new XMPPTCPConnection(connConfig);
try
connection.connect();
Log.i(TAG, "Connected to " + connection.getServiceName());
catch (XMPPException ex)
Log.e(TAG, "Failed to connect to " + connection.getHost());
Log.e(TAG, ex.toString());
return null;
//setConnection(null);
catch (Exception e)
// TODO Auto-generated catch block
e.printStackTrace();
下面是正在获取的堆栈跟踪
12-02 12:56:14.612: W/System.err(23797): javax.net.ssl.SSLException: Connection closed by peer
12-02 12:56:14.622: W/System.err(23797): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
12-02 12:56:14.622: W/System.err(23797): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:378)
12-02 12:56:14.622: W/System.err(23797): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.<init>(OpenSSLSocketImpl.java:649)
12-02 12:56:14.622: W/System.err(23797): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:620)
12-02 12:56:14.622: W/System.err(23797): at org.jivesoftware.smack.tcp.XMPPTCPConnection.initReaderAndWriter(XMPPTCPConnection.java:507)
12-02 12:56:14.622: W/System.err(23797): at org.jivesoftware.smack.tcp.XMPPTCPConnection.initConnection(XMPPTCPConnection.java:457)
12-02 12:56:14.622: W/System.err(23797): at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:440)
12-02 12:56:14.622: W/System.err(23797): at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:811)
12-02 12:56:14.622: W/System.err(23797): at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:396)
12-02 12:56:14.622: W/System.err(23797): at com.mydoc.pro.messenger.net.XMPPConnectAsyncTask.setXMPPConnection(XMPPConnectAsyncTask.java:92)
12-02 12:56:14.622: W/System.err(23797): at com.mydoc.pro.messenger.net.XMPPConnectAsyncTask.doInBackground(XMPPConnectAsyncTask.java:61)
12-02 12:56:14.622: W/System.err(23797): at com.mydoc.pro.messenger.net.XMPPConnectAsyncTask.doInBackground(XMPPConnectAsyncTask.java:1)
12-02 12:56:14.622: W/System.err(23797): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-02 12:56:14.622: W/System.err(23797): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-02 12:56:14.622: W/System.err(23797): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-02 12:56:14.622: W/System.err(23797): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-02 12:56:14.622: W/System.err(23797): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-02 12:56:14.622: W/System.err(23797): at java.lang.Thread.run(Thread.java:856)
12-02 12:56:14.622: I/XMPPConnectAsyncTask(23797): No connection to server null
12-02 12:56:14.622: W/System.err(23797): org.jivesoftware.smack.SmackException$NotConnectedException
12-02 12:56:14.632: W/System.err(23797): at org.jivesoftware.smack.XMPPConnection.sendPacket(XMPPConnection.java:584)
12-02 12:56:14.632: W/System.err(23797): at com.mydoc.pro.messenger.net.XMPPConnectAsyncTask.setXMPPConnection(XMPPConnectAsyncTask.java:117)
12-02 12:56:14.632: W/System.err(23797): at com.mydoc.pro.messenger.net.XMPPConnectAsyncTask.doInBackground(XMPPConnectAsyncTask.java:61)
12-02 12:56:14.632: W/System.err(23797): at com.mydoc.pro.messenger.net.XMPPConnectAsyncTask.doInBackground(XMPPConnectAsyncTask.java:1)
12-02 12:56:14.632: W/System.err(23797): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-02 12:56:14.632: W/System.err(23797): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-02 12:56:14.632: W/System.err(23797): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-02 12:56:14.632: W/System.err(23797): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-02 12:56:14.632: W/System.err(23797): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-02 12:56:14.632: W/System.err(23797): at java.lang.Thread.run(Thread.java:856)
【问题讨论】:
【参考方案1】:connConfig.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
现在正在使用安全模式禁用
【讨论】:
以上是关于XMPP 连接的 asmack-android-8-4.0.6.jar 问题的主要内容,如果未能解决你的问题,请参考以下文章
无法从 Android 在 Ejabberd 服务器中添加新用户。它给出了禁止(403)
XMPP 流发送,不接收。为啥 XMPP 流可能会断开连接?