powered by Jive Software

Smack connection issue

Smack version: 4.4.6

When I try connection with XMPP server I got this isue:

 - java.lang.Exception: java.lang.AssertionError
org.jivesoftware.smack.tcp.rce.RemoteXmppTcpConnectionEndpoints.lookup(RemoteXmppTcpConnectionEndpoints.java:99)
org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:591)
org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:849)
org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:526)
net.kayisoft.familytracker.app.manager.XMPPManager$connect$2.invokeSuspend(XMPPManager.kt:83)

My code:

        withContext(Dispatchers.Default) {
            try {
                val config = XMPPTCPConnectionConfiguration.builder()
                    .setUsernameAndPassword("userName", "Password")
                    .setXmppDomain("Domain")
                    .setPort(32224)
                    .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                    .build()

                XMPPConnection = XMPPTCPConnection(config)

                XMPPConnection?.connect()?.login()
            } catch (error: Throwable) {
                Logger.error(java.lang.Exception(error.stackTraceToString()))
            }
        }

The connection is success after set host as IP

XMPPConnection.setHost(β€œ50.52.271.185”)

why we need set host as IP?

Smack (like all other XMPP clients) will try to perform to resolve the IP address of the server to connect to through DNS records (DNS SRV and DNS A records). If no such records are available, or if the information in them cannot be used to find out where the server to connect to is, then you will need to manually provide that address. I think that this might be what you are running into.

1 Like

Thanks for reply
I tried to connect by another XMPP client without set the IP address and the connect success
why isn’t success in smack without setting the IP address?

The answer to this is very specific to your network configuration as well as the implementation of the other client. I cannot answer that, without knowing all of the details.

You hit the assertion that either there are some discovered remote connection endpoints or there are some lookup failures. However both data structures are empty. If you want to get down to the bottom of this, which I would very much appreciate, since I am unable to reproduce this, then attach an debugger and set a breakpoint at RemoteXmppTcpConnectionEndpoints.java:62 to figure out what is going on.