我已尝试在ios中实现mqtt,但我在发布mqttDidDisconnect时收到错误:" Socket由远程peer"关闭。是服务器上的问题还是发送请求的问题?
deletegate代码
func mqttDidPing(_ mqtt: CocoaMQTT) {
print("mqttDidPing")
}
func mqttDidReceivePong(_ mqtt: CocoaMQTT) {
print("mqttDidReceivePong")
}
func mqtt(_ mqtt: CocoaMQTT, didPublishAck id: UInt16) {
print("didPublishAck : \(id)")
}
func mqtt(_ mqtt: CocoaMQTT, didPublishComplete id: UInt16) {
print("didPublishComplete: \(id)")
}
func mqtt(_ mqtt: CocoaMQTT, didSubscribeTopic topic: String) {
print("didSubscribeTopic: \(topic)")
}
func mqtt(_ mqtt: CocoaMQTT, didUnsubscribeTopic topic: String) {
print("didUnsubscribeTopic: \(topic)")
}
func mqttDidDisconnect(_ mqtt: CocoaMQTT, withError err: Error?) {
print("mqttDidDisconnect: \(err?.localizedDescription ?? "")")
}
func mqtt(_ mqtt: CocoaMQTT, didConnectAck ack: CocoaMQTTConnAck) {
print("didConnectAck: \(ack)")
}
func mqtt(_ mqtt: CocoaMQTT, didPublishMessage message: CocoaMQTTMessage, id: UInt16) {
print("didPublishMessage: \(message) and \(id)")
}
func mqtt(_ mqtt: CocoaMQTT, didReceiveMessage message: CocoaMQTTMessage, id: UInt16) {
print("didReceiveMessage: \(message) and \(id)")
}
func mqtt(_ mqtt: CocoaMQTT, didReceive trust: SecTrust, completionHandler: @escaping (Bool) -> Void) {
print("didReceive trust")
}
答案 0 :(得分:0)
您可以检查我的问题https://github.com/emqtt/CocoaMQTT/issues/252。本质上,问题与服务器端有关,并且使用EMQX代理(从https://github.com/emqx/emqx/releases/download/v3.0.0/emqx-centos7-v3.0.0.zip下载)成功建立了连接
答案 1 :(得分:0)
删除mqtt.willMessage = CocoaMQTTWill(topic:“ / will”,消息:“ dieout”)为我解决了此问题,因为我们的用户无法访问ACL中的/ will主题。