Reputation: 56
How Mqtt Manages internet disconnections ?
void Connection() {
MqtClient client = new MqttClient (brokerEndPoint,brokerPort,false,null,null,MqttSslProtocols.TLSv1_2);
client.MqttMsgPublishReceived += ReceiveFromSubScribedChannel;
client.MqttMsgPublished += ReceivePublishAcknwldg;
client.ConnectionClosed += OnClientdisconnected;
client_id="client_" + UnityEngine.Random.Range (1, 111);
client.Connet(client_id);
}
for me the callback ConnectionClosed is not triggering any messages . Could anyone help me in this regard?
Upvotes: 0
Views: 1309
Reputation: 56
I was able to fix this by connecting the client like below
client.Connet(client_id,username,password,false,3);
where 3 is my keep alive period and I was able to receive the callback.
If Keep alive period is provided to client connection it pings the broker for every 3(keepaliveperiod) seconds and if internet disconnects I can receive a callback in my onconnectionclosed
event
Upvotes: 1