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

Failed to connect to 8883 #566

Closed SkyOfFeather closed 8 months ago

SkyOfFeather commented 8 months ago

When I connected to 1883, the connection was successful, but when I connected to 8883(enableSSL=false), the connection failed with the error 'Socket closed by remote peer'. When I set enableSSL to true, there will also be an error: "Error Domain=kCFStreamErrorDomainSSL Code=-9806" (null) "UserInfo={NSLocalizedRecoverySuggestion=Error code definition can be found in Apple's SecureTransport. h}".

I am testing the iOS 15.1 system. Here is my code:

        let mqtt5 = CocoaMQTT5(clientID: clientId, host: brokerHost, port: 8883)

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

        mqtt5.username = username
        mqtt5.password = password
        mqtt5.willMessage = CocoaMQTT5Message(topic: "/will", string: "dieout")
        mqtt5.keepAlive = 60
        mqtt5.autoReconnect = true
        mqtt5.allowUntrustCACertificate = true
        mqtt5.cleanSession = true
        mqtt5.enableSSL = false
        mqtt5.delegate = self
        let result = mqtt5.connect(timeout: 10)
        print("调用结果: \(result)") 

With the same parameters, I can successfully connect on the mqttx tool. Here is a screenshot of mqttx: WeChat3add04cf643d9e091848b06c587a3693

There is a place to set mqtts://on mqttx. How can I modify the code to achieve the same effect?

leeway1208 commented 8 months ago

Sorry. There is no useful information, Maybe you can find some information from CocoaMQTTCONNACKReasonCode in MqttDecodeConnAck callback. Thanks.

leeway1208 commented 8 months ago

Please refer to this demo CocoaMQTT_reply.zip

afgarcia86 commented 4 months ago

I have the exact same issue if anyone has any suggestions. That Zip just seems like the repo?