Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
leonardo-miguel-silva-alb opened this issue May 22, 2024 · 3 comments

Comments

@leonardo-miguel-silva-alb
Copy link

leonardo-miguel-silva-alb commented May 22, 2024

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
Copy link

+1

2 similar comments
@steveSarsawa-git
Copy link

+1

@jnorgan
Copy link

jnorgan commented Sep 24, 2024

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants