novastone-media / MQTT-Client-Framework

iOS, macOS, tvOS native ObjectiveC MQTT Client Framework
Other
1.84k stars 466 forks source link

Error Domain=MQTT Code=-8 "Server has closed connection without connack." UserInfo={NSLocalizedDescription=Server has closed connection without connack.} #595

Open vidhya11v opened 3 years ago

vidhya11v commented 3 years ago

This is the code which I tried

let sessionManager = MQTTSessionManager() sessionManager.delegate = self

    let userName = ""
    let password = ""

    let certificate = Bundle.main.path(forResource: "ca", ofType: "crt")

    let securityPolicy = MQTTSSLSecurityPolicy.init(pinningMode: .certificate)

    securityPolicy?.allowInvalidCertificates = true

    securityPolicy?.pinnedCertificates = [NSData.init(contentsOfFile: certificate!)!]

    securityPolicy?.validatesCertificateChain = false

    securityPolicy?.validatesDomainName = false

    sessionManager.connect(to: MQTT_HOST, port: Int(MQTT_PORT), tls: true, keepalive: 60, clean: true, auth: false, user: nil, pass: nil, will: false, willTopic: nil, willMsg: nil, willQos: .atMostOnce, willRetainFlag: false, withClientId: "client-1", securityPolicy: securityPolicy, certificates: [NSData.init(contentsOfFile: certificate!)!], protocolLevel: .version311, connectHandler:nil
    )