powered by Jive Software

Smack not reconnecting automatically


#1

Smack Version : 4.2.2

After successfuly connecting to server, when server closes connection, I would like for smack to try to reconnect automatically , for that I have enabled reconnection and stream management like this :

Connection.setUseStreamManagement(true);
        mConnection.setUseStreamManagementResumption(true);
        mConnection.setPreferredResumptionTime(5);
        //Enable auto reconnection when connection is closed for some reason
        ReconnectionManager  reconnectionManager = ReconnectionManager.getInstanceFor(mConnection);
        reconnectionManager.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.FIXED_DELAY);
        reconnectionManager.setFixedDelay(5);
        reconnectionManager.enableAutomaticReconnection();

But when connection is closed by server, it just waits not connecting and only when I send a message does it initiate the reconnection :

01-09 06:36:22.109 7016-7345/com.siter.moko D/SMACK: SENT (0): <message to='user@server.com' id='6xSYC-50' type='chat'><body>Rr</body></message><r xmlns='urn:xmpp:sm:3'/>
01-09 06:36:22.111 7016-7016/com.siter.moko D/ChatMessageAdapter: ChatMessageAdapter knows of the added message
01-09 06:36:43.412 7016-7346/com.siter.moko W/AbstractXMPPConnection: Connection XMPPTCPConnection[user@server.com/Rooster+] (0) closed with error
                                                                         javax.net.ssl.SSLException: Read error: ssl=0x9db1d440: I/O error during system call, Connection reset by peer
                                                                             at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
                                                                             at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:758)
                                                                             at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:287)
                                                                             at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:350)
                                                                             at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:179)
                                                                             at java.io.InputStreamReader.read(InputStreamReader.java:184)
                                                                             at java.io.BufferedReader.read1(BufferedReader.java:221)
                                                                             at java.io.BufferedReader.read(BufferedReader.java:297)
                                                                             at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:42)
                                                                             at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1516)
                                                                             at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:993)
                                                                             at org.kxml2.io.KXmlParser.next(KXmlParser.java:349)
                                                                             at org.kxml2.io.KXmlParser.next(KXmlParser.java:313)
                                                                             at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1244)
                                                                             at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:994)
                                                                             at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:1010)
                                                                             at java.lang.Thread.run(Thread.java:761)
01-09 06:36:43.412 7016-7346/com.siter.moko D/RConnection: ConnectionClosedOnError
01-09 06:36:43.413 7016-7346/com.siter.moko D/RConnection: Sent the broadcast for connection Error
01-09 06:36:43.414 7016-7346/com.siter.moko D/SMACK: XMPPConnection closed due to an exception (XMPPTCPConnection[user@server.com/Rooster+] (0))
                                                        javax.net.ssl.SSLException: Read error: ssl=0x9db1d440: I/O error during system call, Connection reset by peer
                                                            at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
                                                            at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:758)
                                                            at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:287)
                                                            at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:350)
                                                            at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:179)
                                                            at java.io.InputStreamReader.read(InputStreamReader.java:184)
                                                            at java.io.BufferedReader.read1(BufferedReader.java:221)
                                                            at java.io.BufferedReader.read(BufferedReader.java:297)
                                                            at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:42)
                                                            at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1516)
                                                            at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:993)
                                                            at org.kxml2.io.KXmlParser.next(KXmlParser.java:349)
                                                            at org.kxml2.io.KXmlParser.next(KXmlParser.java:313)
                                                            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1244)
                                                            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:994)
                                                            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:1010)
                                                            at java.lang.Thread.run(Thread.java:761)
01-09 06:36:44.416 7016-7420/com.siter.moko D/SMACK: XMPPConnection (XMPPTCPConnection[user@server.com/Rooster+] (0)) will reconnect in 4
01-09 06:36:44.416 7016-7420/com.siter.moko D/RConnection: Reconnecting in 4 seconds
01-09 06:36:45.418 7016-7420/com.siter.moko D/SMACK: XMPPConnection (XMPPTCPConnection[user@server.com/Rooster+] (0)) will reconnect in 3
01-09 06:36:45.418 7016-7420/com.siter.moko D/RConnection: Reconnecting in 3 seconds
01-09 06:36:46.420 7016-7420/com.siter.moko D/SMACK: XMPPConnection (XMPPTCPConnection[user@server.com/Rooster+] (0)) will reconnect in 2
01-09 06:36:46.420 7016-7420/com.siter.moko D/RConnection: Reconnecting in 2 seconds
01-09 06:36:47.422 7016-7420/com.siter.moko D/SMACK: XMPPConnection (XMPPTCPConnection[user@server.com/Rooster+] (0)) will reconnect in 1
01-09 06:36:47.422 7016-7420/com.siter.moko D/RConnection: Reconnecting in 1 seconds
01-09 06:36:48.425 7016-7420/com.siter.moko D/SMACK: XMPPConnection (XMPPTCPConnection[user@server.com/Rooster+] (0)) will reconnect in 0
01-09 06:36:48.425 7016-7420/com.siter.moko D/RConnection: Reconnecting in 0 seconds
01-09 06:36:48.427 7016-7420/com.siter.moko D/SMACK: XMPPConnection (XMPPTCPConnection[user@server.com/Rooster+] (0)) will reconnect in 0
01-09 06:36:48.427 7016-7420/com.siter.moko D/RConnection: Reconnecting in 0 seconds

Is there anything else I need to do to have it reconnect automatically ?

Thanks.