Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After internet connection returns mqtt connection doesn't regain #57

Open
NikhilGangurde opened this issue Apr 2, 2021 · 0 comments
Open

Comments

@NikhilGangurde
Copy link

NikhilGangurde commented Apr 2, 2021

Scenario: I am using MQTT for a game firstly user plays for sometimes MQTT works great then I turn off my internet for 5 sec it's off and then the connection turns on again then the connection doesn't establish again only shows reconnecting after a time interval of 35 sec.

For client id, I am using email id(unique)

Code:

func mqttDidDisconnect(session: MQTTSession, error: MQTTSessionError) {
        print("Session Disconnected.")
        if error != .none {
            print("mqttDidDisconnect",error.description)
        }
        reconnectMqttConnection()
    }
    
    func mqttDidAcknowledgePing(from session: MQTTSession) {
        print("Keep-alive ping acknowledged. \(Date())")
        mqttTimer?.invalidate()
        mqttTimer = nil
        mqttTimer = Timer.scheduledTimer(timeInterval: 35.0, target: self, selector: #selector(reconnectMqttConnection), userInfo: nil, repeats: true)
    }
    
    @objc func reconnectMqttConnection() {
        print("********* reconnectMqttConnection ***********")
        mqttSession.disconnect()
        mqttSession = nil
        establishConnection(clientID, matchID: matchID)
    }

Error Log in console After internet connection is turned on again:

********* reconnectMqttConnection *********** 
Trying to connect for client
Session Disconnected.
mqttDidDisconnect Stream Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant