SwiftMQTT icon indicating copy to clipboard operation
SwiftMQTT copied to clipboard

Reconnection issue

Open NancyZY opened this issue 8 years ago • 5 comments

How to deal with the reconnection,? I try to in mqttDidDisconnect method call the connection method, Is it right action?

NancyZY avatar Nov 16 '16 09:11 NancyZY

Yes, what is the actual issue that you are facing?

bhargavg avatar Nov 16 '16 10:11 bhargavg

when I use the library to app, it connect successfully, but sometimes it may disconnected, then I tried to in mqttDidDisconnect method call the connection method, like below code:func mqttDidDisconnect(session: MQTTSession) { connect(session) print("Session Disconnected.") }, the result shows 6596 Connection has no connected handler? what does it mean?

NancyZY avatar Nov 17 '16 08:11 NancyZY

From the error message, I guess the session delegate is getting deallocated.

Also, what is connect(session) method doing? Why does it need an already closed session to reconnect again?

bhargavg avatar Nov 17 '16 15:11 bhargavg

Because I want the connection always keep alive. I use it to receive the other client published message. And if it disconnect, it should try to connect. The connect(session) method is like that :

func connect(_ mqttSession : MQTTSession) -> Void {
        mqttSession.connect {
            if !$0 {
                print("Error Occurred During connection \($1)")
                return
            }
            mqttSession.subscribe(to: "topic", delivering: .atLeastOnce) { (succeeded, error) -> Void in
                if succeeded {
                    print("Subscribed!")
                }
            }
        }
    }```
,  Is everything right here ?

NancyZY avatar Nov 18 '16 02:11 NancyZY

i am using same SwiftMQTT only , canu tell me how subscribe with Messege, i am getting only subscribe name

mahesh07513 avatar Feb 09 '17 18:02 mahesh07513