powered by Jive Software

Android smack 4.2.2 login must after timeout

Hello there,

I’m using

  • Android / Kotlin
  • Smack 4.4.2
  • Openfire 4.3.2

I’m using the following code to connect Openfire server

    fun connectToXMPPServer() {
        Thread {
            run {
                try {
                    val configBuilder = XMPPTCPConnectionConfiguration.builder()
//                    .setHostAddress(InetAddress.getByName(XMPP_SERVER))
                    .setHost(XMPP_SERVER)
                    .setXmppDomain(XMPP_SERVER)
                    .setPort(XMPP_PORT)
                    .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                    .enableDefaultDebugger()
                    .setCompressionEnabled(true)
                    .setSendPresence(false)
                    .setUsernameAndPassword(PUBLIC_AC, PUBLIC_PW)
                    mConnection = XMPPTCPConnection(configBuilder.build())
                    mConnection?.replyTimeout = 3000
                    mConnection?.setUseStreamManagement(false)
                    mConnection?.setUseStreamManagementResumption(false)

                    mConnection?.setParsingExceptionCallback {
                        print(it.content)
                    }
                    mConnection?.addConnectionListener(object : ConnectionListener {
                        override fun connecting(connection: XMPPConnection?) {
                            super.connecting(connection)
                        }

                        override fun connected(connection: XMPPConnection?) {
                            mConnection?.login()
                            setAvailable()
                        }

                        override fun authenticated(connection: XMPPConnection?, resumed: Boolean) {
                            super.authenticated(connection, resumed)
                        }

                        override fun connectionClosed() {
                            super.connectionClosed()
                        }

                        override fun connectionClosedOnError(e: java.lang.Exception?) {
                            super.connectionClosedOnError(e)
                        }
                    })
                    mConnection?.connect()
                } catch (e: UnknownHostException) {
                    e.printStackTrace()
                    Log.d(TAG, e.toString())
                } catch (e: XmppStringprepException) {
                    e.printStackTrace()
                    Log.d(TAG, e.toString())
                } catch (e: InterruptedException) {
                    e.printStackTrace()
                    Log.d(TAG, e.toString())
                } catch (e: IOException) {
                    e.printStackTrace()
                    Log.d(TAG, e.toString())
                } catch (e: SmackException) {
                    e.printStackTrace()
                    Log.d(TAG, e.toString())
                } catch (e: XMPPException) {
                    createAccount()
                    mConnection?.login()
                    setAvailable()
//                    mConnection?.login()
                    e.printStackTrace()
                    Log.d(TAG, e.toString())
                }
            }
        }.start()

    }

When calling

mConnection?.login()

It must be waiting for

mConnection?.replyTimeout = 3000

(default 5second) or my custom setting(3 second) first, then successfully login.
Here is the following message :

W/DataFormProvider: The Field 'admin-addresses' from FORM_TYPE 'http://jabber.org/network/serverinfo' is not registered. Field type is unknown, assuming text-single.
W/HttpFileUploadManager: Error during discovering HTTP File Upload service
    org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=HKJTW-2)), : fromFilter (OrFilter: (FromMatchesFilter (full): stdevzone.com)).
        at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:281)
        at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:228)
        at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.discoverInfo(ServiceDiscoveryManager.java:606)
        at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.discoverInfo(ServiceDiscoveryManager.java:578)
        at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.findServicesDiscoverInfo(ServiceDiscoveryManager.java:813)
        at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.findServicesDiscoverInfo(ServiceDiscoveryManager.java:781)
        at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.findServicesDiscoverInfo(ServiceDiscoveryManager.java:761)
        at org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager.discoverUploadService(HttpFileUploadManager.java:192)
        at org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager$2.authenticated(HttpFileUploadManager.java:129)
        at org.jivesoftware.smack.AbstractXMPPConnection.callConnectionAuthenticatedListener(AbstractXMPPConnection.java:1704)
        at org.jivesoftware.smack.AbstractXMPPConnection.afterSuccessfulLogin(AbstractXMPPConnection.java:795)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection.afterSuccessfulLogin(XMPPTCPConnection.java:371)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginInternal(XMPPTCPConnection.java:469)
        at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:641)
        at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:598)
        at com.stdevzone.supernotification.MessageService$connectToXMPPServer$1$1$2.connected(MessageService.kt:259)
        at org.jivesoftware.smack.AbstractXMPPConnection.callConnectionConnectedListener(AbstractXMPPConnection.java:1697)
        at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:545)
        at com.stdevzone.supernotification.MessageService.connectToXMPPServer$lambda-2(MessageService.kt:275)
        at com.stdevzone.supernotification.MessageService.lambda$cMHxciJl94aHanccTGpX9en83a4(Unknown Source:0)
        at com.stdevzone.supernotification.-$$Lambda$MessageService$cMHxciJl94aHanccTGpX9en83a4.run(Unknown Source:2)
        at java.lang.Thread.run(Thread.java:919)

A URL in the message

The Field 'admin-addresses' from FORM_TYPE 'http://jabber.org/network/serverinfo' is not registered. Field type is unknown, assuming text-single.

http://jabber.org/network/serverinfo
Which is a 404 not found page
Is it related to my issue?
If not, any solution to fix it?

Thx :slight_smile:

Probably not.

Smacks’s telling you that it did not receive a response to an IQ request it send. That is something that should not happen, so you definitely want to look into that. A XMPP trace would be a good next step, see How to ask for help, report an issue and possible solve the problem yourself · igniterealtime/Smack Wiki · GitHub.

The “service discovery” issue seems to be caused by a combination of two factors:

  1. an Openfire omission, fixed in Openfire v4.6.0 (OF-2054)
  2. Smack becoming more strict in this area, starting with Smack v4.4.0

As a result, I would expect you to run into this issue whenever you use an Openfire version prior to v4.6.0 in combination with any Smack-based application that is built on Smack v4.4.0 or later.

If you would like to use a combination of versions that suffer from this problem (eg: a ‘newer’ version of Smack with your existing v4.3.2 of Openfire), then there is a workaround that you can apply: by setting the Openfire property “admin.disable-exposure” to “true” you will prevent Openfire from sending out the stanza that will trip up Smack.