emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.57k stars 411 forks source link

MQTT client does not connect, disconnects after receiving 0 data from broker #596

Open leonardo-miguel-silva-alb opened 1 month ago

leonardo-miguel-silva-alb commented 1 month ago

Hi, As the titles indicates my client is closing after receiving 0 data from broker. My broker uses a Self Signed Certificate. Next I will indicate my code and logs

`
func selfSignedSSLSetting() { if mqttVesion == "3.1.1" {

        let clientID = "CocoaMQTT-\(animal!)-"
        mqtt = CocoaMQTT(clientID: clientID, host: defaultHost, port: 1883)
        mqtt!.username = "xxx"
        mqtt!.password = "xxx"
        mqtt!.keepAlive = 60
        mqtt!.delegate = self
        mqtt!.allowUntrustCACertificate = true
        mqtt!.logLevel = .debug

    }else if mqttVesion == "5.0" {

        let clientID = "CocoaMQTT5-\(animal!)-"
        mqtt5 = CocoaMQTT5(clientID: clientID, host: defaultHost, port: 1883)

        let connectProperties = MqttConnectProperties()
        connectProperties.topicAliasMaximum = 0
        connectProperties.sessionExpiryInterval = 0
        connectProperties.receiveMaximum = 100
        connectProperties.maximumPacketSize = 500

        mqtt5!.connectProperties = connectProperties
        mqtt5!.logLevel = .debug

        mqtt5!.username = "xxx"
        mqtt5!.password = "xxx"
        mqtt5!.keepAlive = 60
        mqtt5!.delegate = self

        mqtt5!.allowUntrustCACertificate = true

    }

}`

`[TRACE] [didStateChangeTo]: new state: connecting

CocoaMQTT(info): Connected to xx.xx.xx.xxx : 1883 CocoaMQTT(info): Enable backgrounding socket successfully CocoaMQTT(debug): SEND: CONNECT(id: CocoaMQTT-Sheep-, username: xxx, password: xxx, keepAlive : 60, cleansess: true) CocoaMQTT(debug): =========================MQTT 3.1.1========================= CocoaMQTT(debug): packetFixedHeaderType 16 CocoaMQTT(debug): remainingLen(len: len) [68] CocoaMQTT(debug): variableHeader something CocoaMQTT(debug): payload something CocoaMQTT(debug): ============================================================= CocoaMQTT(debug): socket wrote data 0 CocoaMQTT(debug): socket disconnected

[TRACE] [didDisconnect]: Error Domain=NSPOSIXErrorDomain Code=54 "Connection reset by peer" UserInfo={NSLocalizedDescription=Connection reset by peer, NSLocalizedFailureReason=Error in read() function} [TRACE] [didStateChangeTo]: new state: disconnected`

magnusfernandes commented 1 month ago

+1