emqx / CocoaMQTT

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

Socket closed by remote peer #454

Closed jmjaimesmendoza closed 2 years ago

jmjaimesmendoza commented 2 years ago

Hi, i have the following issue immediately after trying to subscribe to a topic via MQTT5. I've tried both Mosquitto and HiveMQ brokers and both have the same issue, only way to successfully subscribe to a topic is to use the broker in the Example App. Any help is greatly appreciated!

These are my current settings:

    `let clientID = "CocoaMQTT5-JMJM-" + String(ProcessInfo().processIdentifier)
    mqtt5 = CocoaMQTT5(clientID: clientID, host: defaultHost, port: 1883)
    mqtt5!.logLevel = .debug
    let connectProperties = MqttConnectProperties()
    connectProperties.topicAliasMaximum = 0
    connectProperties.sessionExpiryInterval = 0
    connectProperties.receiveMaximum = 100
    connectProperties.maximumPacketSize = 500

    mqtt5!.connectProperties = connectProperties
    mqtt5!.username = ""
    mqtt5!.password = ""

    let lastWillMessage = CocoaMQTT5Message(topic: "/will", string: "dieout")
    lastWillMessage.contentType = "JSON"
    lastWillMessage.willResponseTopic = "/will"
    lastWillMessage.willExpiryInterval = 0
    lastWillMessage.willDelayInterval = 0
    lastWillMessage.qos = .qos1

    mqtt5!.willMessage = lastWillMessage
    mqtt5!.keepAlive = 60
    mqtt5!.delegate = self
    //mqtt5!.autoReconnect = true
    mqtt5!.connect()`

My subscribe command is: mqtt5!.subscribe("jmjm/testing",qos: CocoaMQTTQoS.qos1)

( I guess the issue lies with broker side settings, but i have no clue which changes to make if that is the case, especially because I'm using on official test brokers)

jmjaimesmendoza commented 2 years ago

Already did!, the client connected successfully but the problem occured when i tried to publish/subscribe.

Anyways, i tried switching from MQTTv5 to MQTTv3.1.1 and that fixed pretty much all issues regarding subscribe/publish with those 2 testing brokers.

Thanks nonetheless!