本文介绍了Asmack中的ReconnectionManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android上有一个项目,该项目需要使用asmack库来启用实时聊天.

I have a project on Android, which needs to use asmack library to enable real time chat.

关键功能是重新连接机制,这意味着我的应用程序可以在互联网连接断开时自动重新连接.

The key feature is reconnecting mechanism, that means my application can reconnect automatically whenever the internet connection loses.

这是我的代码段:

ConnectionConfiguration connConfig = new ConnectionConfiguration(HOST, PORT);
connConfig.setSASLAuthenticationEnabled(true);
connConfig.setReconnectionAllowed(true);
XMPPConnection connection = new XMPPConnection(connConfig);

但是,每当我关闭然后打开Wifi上网时,我都会收到此错误消息:

But I got this error whenever I turned off then turned on Wifi:

10-01 21:43:26.942: W/System.err(13695): javax.net.ssl.SSLException: Write error: ssl=0x5a4ad348: I/O error during system call, Broken pipe
10-01 21:43:27.002: W/System.err(13695):    at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_write(Native Method)
10-01 21:43:27.012: W/System.err(13695):    at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:693)
10-01 21:43:27.012: W/System.err(13695):    at java.io.OutputStreamWriter.flushBytes(OutputStreamWriter.java:167)
10-01 21:43:27.012: W/System.err(13695):    at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:158)
10-01 21:43:27.012: W/System.err(13695):    at java.io.BufferedWriter.flush(BufferedWriter.java:124)
10-01 21:43:27.012: W/System.err(13695):    at org.jivesoftware.smack.PacketWriter.writePackets(PacketWriter.java:210)
10-01 21:43:27.012: W/System.err(13695):    at org.jivesoftware.smack.PacketWriter.access$000(PacketWriter.java:42)
10-01 21:43:27.012: W/System.err(13695):    at org.jivesoftware.smack.PacketWriter$1.run(PacketWriter.java:78)
10-01 21:43:27.092: W/System.err(13695): javax.net.ssl.SSLException: Read error: ssl=0x5a4ad348: I/O error during system call, Connection timed out
10-01 21:43:27.092: W/System.err(13695):    at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read(Native Method)
10-01 21:43:27.092: W/System.err(13695):    at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:651)
10-01 21:43:27.092: W/System.err(13695):    at java.io.InputStreamReader.read(InputStreamReader.java:244)
10-01 21:43:27.092: W/System.err(13695):    at java.io.BufferedReader.read(BufferedReader.java:310)
10-01 21:43:27.092: W/System.err(13695):    at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1496)
10-01 21:43:27.092: W/System.err(13695):    at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:979)
10-01 21:43:27.092: W/System.err(13695):    at org.kxml2.io.KXmlParser.next(KXmlParser.java:346)
10-01 21:43:27.092: W/System.err(13695):    at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
10-01 21:43:27.092: W/System.err(13695):    at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:326)
10-01 21:43:27.092: W/System.err(13695):    at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
10-01 21:43:27.092: W/System.err(13695):    at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:71)

可以解决此错误的任何人,请帮助我!

Anyone, who can solve this error, please help me!

推荐答案

使用最新的smack api-我正在使用4.1.0

Use the latest smack api - I am using 4.1.0

然后按如下所示建立重新连接:

Then set up re-connection like below:

ReconnectionManager manager = ReconnectionManager.getInstanceFor(connection);
manager.enableAutomaticReconnection();

它会按照这里

这篇关于Asmack中的ReconnectionManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 19:15