I am implementing for chat application in iOS Swift. Backend is in MongooseIM. I am facing problem in connection. Connection is taking 7 to 8 seconds.
My flow of connection is below:
When I open application I am sending following
self.xmppStream.myJID = UIDevice.current.identifierForVendor.map { userJID.withNewResource($0.uuidString) } ?? userJID
self.xmppStream.hostPort = hostPort
self.xmppStream.hostName = Constants.kServerName
self.password = password
self.xmppStream.enableBackgroundingOnSocket = true
self.xmppStream.keepAliveInterval = 0.5;
self.xmppReconnect.manualStart()
after 3 to 4 seconds approximately, xmppStreamDidConnect delegate method called.
in xmppStreamDidConnect method, I am sending stream authentication like below
stream.authenticate(withPassword: self.password)
again after 3 to 4 seconds, xmppStreamDidAuthenticate method called.
so, total process is taking 7 to 8 seconds, this is too much time. I also check logs from server. in server log, connect time is 3 seconds and and authentication time is less than 1 seconds.
Each time when app is open, I am doing above process to establish connection
Can anybody help me to optimize it? Is there anyway to check where this time is spending. Is this correct way for establish connection ?
If anybody need more information, I can provide. Thank you so much!