SwiftMQTT
SwiftMQTT copied to clipboard
Reconnection issue
How to deal with the reconnection,? I try to in mqttDidDisconnect method call the connection method, Is it right action?
Yes, what is the actual issue that you are facing?
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?
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?
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 ?
i am using same SwiftMQTT only , canu tell me how subscribe with Messege, i am getting only subscribe name