Mqtt如何管理互联网断线?
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);
}
对我来说,回调ConnectionClosed没有触发任何消息。在这方面有人能帮助我吗?
答案 0 :(得分:0)
我能够通过连接客户端来解决这个问题,如下所示
client.Connet(client_id,username,password,false,3);
其中3是我的活着期,我能够收到回调。
如果为客户端连接提供保持活动期间,它会每隔3(keepaliveperiod)秒对代理进行ping操作,如果互联网断开连接,我可以在onconnectionclosed
事件中收到回调