使用MQTT时遇到一直断线重连的问题,排查了很久,最后才发现设置的ClientId都是一样的。
如果有特殊规则,设置的时候请保证ClientId不要重复,没有特殊规则的话建议设置为nil。
* @param clientId The Client Identifier identifies the Client to the Server. If nil, a random clientId is generated.
[self.manager connectTo:@"地址" port:@"端口号" tls:NO keepalive:60 clean:NO auth:YES user:MqttUser pass:MqttUserPwd will:NO willTopic:nil willMsg:nil willQos:(MQTTQosLevelAtMostOnce) willRetainFlag:NO withClientId:nil securityPolicy:nil certificates:nil protocolLevel:(MQTTProtocolVersion311) connectHandler:^(NSError *error) {
if (error == nil) {
NSLog(@"MQTT连接成功");
}else{
NSLog(@"MQTT Error%@",error.localizedDescription);
}
}];
网友评论