Lossing connection in android

Hi i have a problem in my android app. It keep loosing connection and reconnect after a few seconds or minutes. I checked my android logs and get this message:

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): Connection closed with error

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): javax.net.ssl.SSLException: Read error: ssl=0x79667e40: I/O error during system call, Connection reset by peer

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketIm pl.java:690)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at java.io.InputStream.read(InputStream.java:162)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:194)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:153)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at java.io.InputStreamReader.read(InputStreamReader.java:233)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at java.io.BufferedReader.read(BufferedReader.java:325)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:41)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1506)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:986)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at org.kxml2.io.KXmlParser.next(KXmlParser.java:346)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:1165)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPCon nection.java:944)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnecti on.java:959)

11-27 14:26:22.526: W/AbstractXMPPConnection(4852): at java.lang.Thread.run(Thread.java:841)

11-27 14:26:22.526: D/SMACK(4852): XMPPConnection closed due to an exception (0)

11-27 14:26:22.526: W/System.err(4852): javax.net.ssl.SSLException: Read error: ssl=0x79667e40: I/O error during system call, Connection reset by peer

11-27 14:26:22.526: W/System.err(4852): at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)

11-27 14:26:22.526: W/System.err(4852): at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketIm pl.java:690)

11-27 14:26:22.526: W/System.err(4852): at java.io.InputStream.read(InputStream.java:162)

11-27 14:26:22.526: W/System.err(4852): at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:194)

11-27 14:26:22.536: W/System.err(4852): at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:153)

11-27 14:26:22.536: W/System.err(4852): at java.io.InputStreamReader.read(InputStreamReader.java:233)

11-27 14:26:22.536: W/System.err(4852): at java.io.BufferedReader.read(BufferedReader.java:325)

11-27 14:26:22.536: W/System.err(4852): at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:41)

11-27 14:26:22.536: W/System.err(4852): at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1506)

11-27 14:26:22.536: W/System.err(4852): at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:986)

11-27 14:26:22.536: W/System.err(4852): at org.kxml2.io.KXmlParser.next(KXmlParser.java:346)

11-27 14:26:22.536: W/System.err(4852): at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)

11-27 14:26:22.536: W/System.err(4852): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:1165)

11-27 14:26:22.536: W/System.err(4852): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPCon nection.java:944)

11-27 14:26:22.536: W/System.err(4852): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnecti on.java:959)

11-27 14:26:22.536: W/System.err(4852): at java.lang.Thread.run(Thread.java:841)

Can anyone explain me what is this error i get? The strange thing is that i have this problem only with android 4.4.2.

Same problem since Android marshmallow…any glue?

Your TCP connection is reset by the peer.

I never had this problem on android lollipop or below. I updated before two days, since this update to Marshmallow connection is allways closed by going into sleepmode. So this must be a android 6 problem…ideas to handle that?

You need to whitelist your app for network access while in sleep mode on Android 6.0 or higher: Optimizing for Doze and App Standby | Android Developers

No success, thanks for your suggestions, but all this I have done. I first tried with all that solutions and I have informed myself very well about that different possibillities. I guess that this is a problem by the new “final” Marshmallow version from Huawei for Huawei Ascend Mate 7. Maybe this also happens on other devices. The App is added to whitelist, is protected, will not be optimized by the power manager etc. absolutely nothing works…

Absolutely possible that manufacturer modifications break the Android API contract. It happened before. Unfortunately this means you can’t properly use XMPP on those devices without resorting to GCM/xep357 (something that should not be required for whitelisted apps using XMPP), or installing a compliant Android version.

This is absolutely disappointing from both sides, Google and Huawei. Limiting that to GCM is an Apple-Like-Behaviour . I know there are some possible ways for a developer, but at the end, it depends on the user. And, seriously, on some devices the settings for keep apps alive are not user-friendly implemented and scattered in the settings. A usual user won´t find all necessary settings and will be annoyed and maybe blames that app because of no knowledge. What Google has done to android, only for saving battery (in these days, batteries becomes better, so not really necessary)?

I read many topics about annoyed users since they updated to Marshmallow and now I understand them…

Why blame Google? Vanilla Android just requires the users to whitelist the app once and Android is even so kind to provide an API to lead the user to the correct setting activity.

Besides keeping a long lived TCP connection is not required by 99% of all Android apps. The other apps could use GCM (no user interaction required). Using XMPP on Android without Google Service is, sadly, a nice use case.

It could be even worse, the first L previews had already the doze mode but not the whitelist feature. If they would have kept it that way in the final version, then it would be impossible to use XMPP on Android 6.0 without GCM.

yeah, you are correct, it could be worse. I´m just a little bit upset because if I think on a normal user who has no technical experience, he won´t ever find all the settings that let apps do their job. But it´s maybe only in Huawei mate 7…there are 13 different settings only to prevent an app from beeing disabled from network connection or go to sleep or being killed…and so on…