Smack Version:
4.4.0 beta2 but observed with 4.3.4 also
Gradle entries
implementation "org.igniterealtime.smack:smack-android-extensions:4.4.0-beta2"
implementation "org.igniterealtime.smack:smack-tcp:4.4.0-beta2"
The Problem:
I have a connection delay that I cannot find explanations. Basically the connection to the local machine takes almost 1min in the Emulator and 20s+ on the physical device. I have tried everything I know and ended up with the code below. The time on device is now around 15s (after disabling the debug), but it is still a lot for just connecting.
Am not doing anything complex, just connecting.
Anyone with idea what I can do to optimize the delay?
Code:
class XMPPConnectionManager {
companion object {
const val JABBER_DOMAIN = "localhost"
const val JABBER_URL = "192.168.1.101"
const val JABBER_RESOURCE = "Resource"
const val JABBER_PORT = 5222
const val CONNECTION_TIMEOUT = 300
const val REPLY_TIMEOUT = 30000L
}
private val conn: XMPPTCPConnection by lazy {
val builder = XMPPTCPConnectionConfiguration.builder()
.setXmppDomain(JidCreate.domainBareFrom(JABBER_DOMAIN))
.setHostAddress(InetSocketAddress(JABBER_URL, JABBER_PORT).address)
.setResource(JABBER_RESOURCE)
.setCompressionEnabled(true)
.setSendPresence(false)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled) //TODO: Enable it
//.enableDefaultDebugger()
.setConnectTimeout(CONNECTION_TIMEOUT)
val connection = XMPPTCPConnection(builder.build())
connection.replyTimeout = REPLY_TIMEOUT
//auto reconnection
val reconnectionManager = ReconnectionManager.getInstanceFor(connection)
reconnectionManager.enableAutomaticReconnection()
reconnectionManager.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.RANDOM_INCREASING_DELAY)
connection.connect()
return@lazy connection
}
fun login(username: String?, password: String?): Boolean {
try {
if (!conn.isConnected) {
conn.connect()
}
if(!conn.isAuthenticated){
conn.login(username, password)
//Setup OX-IM and other listeners
}
} catch (e: Exception) {
return false
}
return true
}
}