我尝试在ios中实现mqtt,但在发布mqttDidDisconnect时收到一个错误:“远程对等方关闭了套接字”。是服务器上的问题还是发送请求时的问题?
删除门代码
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")
}
最佳答案
你可以查看我的问题https://github.com/emqtt/CocoaMQTT/issues/252。本质上,问题是与服务器端相关的,并且使用EMQX代理连接成功(从https://github.com/emqx/emqx/releases/download/v3.0.0/emqx-centos7-v3.0.0.zip下载)