aciidgh / SwiftMQTT

MQTT Client in pure swift ❤️
MIT License
270 stars 71 forks source link

Reconnection issue #15

Open NancyZY opened 7 years ago

NancyZY commented 7 years ago

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

bhargavg commented 7 years ago

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

NancyZY commented 7 years ago

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?

bhargavg commented 7 years ago

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?

NancyZY commented 7 years ago

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 ?
mahesh07513 commented 7 years ago

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