0

Sending and receiving message with XMPP is working charm if my connection is established, But the only problem is Connection is lost with error frequently and It throws exceptions. I don't know where I have done mistake. I'm kind of lost in XMPP. Here is connection which I've established and Exception as well.

public AbstractXMPPConnection getXMPPConnection() {

        try {

            Log.i(TAG, "getXMPPConnection: userLogin >> " + mSharedPrefs.getXMPPLoginUserName() + "@" + Constant.XMPP_HOST);

            SmackConfiguration.DEBUG = true;

            /**
             * Set XMPP configuration with server
             */
            XMPPTCPConnectionConfiguration mXmppTcpConnectionConfiguration = XMPPTCPConnectionConfiguration.builder()
                    .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                    .setServiceName(Constant.XMPP_SERVICE_NAME)
                    .setHost(Constant.XMPP_HOST)
                    .setUsernameAndPassword(mSharedPrefs.getXMPPLoginUserName(), Constant.XMPP_USER_PASSWORD)
                    .setPort(Constant.XMPP_PORT)
                    .setDebuggerEnabled(true)
                    .setCompressionEnabled(true)
                    .build();

            /**
             * Apply XMPP configuration to connection
             */
            mAbstractXMPPConnection = new XMPPTCPConnection(mXmppTcpConnectionConfiguration);
            mAbstractXMPPConnection.setPacketReplyTimeout(Constant.XMPP_PACKET_REPLY_TIMEOUT);

            SASLAuthentication.blacklistSASLMechanism(Constant.XMPP_BLACKLIST_SSL_MECHANISM);
            SASLAuthentication.unBlacklistSASLMechanism(Constant.XMPP_UNBLACKLIST_SSL_MECHANISM);

            mAbstractXMPPConnection.connect();

            Presence presence = new Presence(Presence.Type.available);
            mAbstractXMPPConnection.sendStanza(presence);

            mAbstractXMPPConnection.addConnectionListener(new ConnectionListener() {

                @Override
                public void reconnectionSuccessful() {
                    Log.e(TAG, "Successfully reconnected to the XMPP server.");

                }

                @Override
                public void reconnectionFailed(Exception arg0) {
                    Log.e(TAG, "Failed to reconnect to the XMPP server.");
                }

                @Override
                public void reconnectingIn(int seconds) {
                    Log.e(TAG, "Reconnecting in " + seconds + " seconds.");
                }

                @Override
                public void connectionClosedOnError(Exception e) {

                    Log.e(TAG, "Connection to XMPP server is lost with Error.");
                    e.printStackTrace();

                    new XMPPConnectionAsync(mContext).execute();

                }

                @Override
                public void connected(org.jivesoftware.smack.XMPPConnection connection) {
                    Log.e(TAG, "connected: ");
                }

                @Override
                public void authenticated(org.jivesoftware.smack.XMPPConnection connection, boolean resumed) {
                    Log.e(TAG, "Connection is authenticated: ");
                }

                @Override
                public void connectionClosed() {
                    Log.e(TAG, "XMPP connection was closed.");

                }
            });


            /**
             *   Check if connected successfully
             */
            if (mAbstractXMPPConnection.isConnected()) {

                Log.i(TAG, "getXMPPConnection: Connection is Successful!!");

                mAbstractXMPPConnection.login(mSharedPrefs.getXMPPLoginUserName() + "@" + Constant.XMPP_HOST, Constant.XMPP_USER_PASSWORD);
                Constant.XMPP_IS_CONNECTED = true;

            }

        } catch (SmackException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XMPPException e) {
            e.printStackTrace();
        }

        return mAbstractXMPPConnection;
    }

And here is an exception.

10-25 12:44:51.340 19016-3219/com.inhertix.socialapp E/XMPPConnection: Connection to XMPP server was lost.
10-25 12:44:51.340 19016-3219/com.inhertix.socialapp W/System.err: org.jivesoftware.smack.XMPPException$StreamErrorException: conflict You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions
10-25 12:44:51.340 19016-3219/com.inhertix.socialapp W/System.err: <stream:error><conflict xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error>
10-25 12:44:51.340 19016-3219/com.inhertix.socialapp W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:996)
10-25 12:44:51.340 19016-3219/com.inhertix.socialapp W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:937)
10-25 12:44:51.340 19016-3219/com.inhertix.socialapp W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:952)
10-25 12:44:51.340 19016-3219/com.inhertix.socialapp W/System.err:     at java.lang.Thread.run(Thread.java:818)
Kuls
  • 2,047
  • 21
  • 39
  • May I suggest reading the exception message? It says: "StreamErrorException: conflict You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions" – Flow Oct 25 '16 at 16:34
  • Thanks for the suggestion @Flow . But I ain't figured out what to do further. – Kuls Oct 27 '16 at 09:32

0 Answers0