Skip to content

Disconnect: The operation couldn’t be completed. Socket is not connected #605

@steveSarsawa-git

Description

@steveSarsawa-git

I'm facing issue, like whenever i tried to established connection through Mobile data. MQTT getting disconnected automatically, and if i tried to reconnect getting below error. In android and React native iOS App is working fine. But issue i'm facing only in Swift iOS. I've tried all the possible ways, with enable ssl, without ssl. allowUntrustedCertificates and so on. But nothing is helping here

  • error

Disconnect: The operation couldn’t be completed. Socket is not connected

  • Code
            let scoket = CocoaMQTTWebSocket(uri: "/ws")
            scoket.enableSSL = false
            try? scoket.connect(toHost: host, onPort: UInt16(port))
            
            mqttClient = CocoaMQTT(clientID: clientId, host: host, port: UInt16(port), socket: scoket)
            
            if let mqttClient = mqttClient {
                UserManager.shared.isConnected = true
                mqttClient.username = username
                mqttClient.password = password
                mqttClient.keepAlive = UInt16(60)
                mqttClient.cleanSession = cleanSession
                mqttClient.backgroundOnSocket = true
                mqttClient.logLevel = .debug
                mqttClient.deliverTimeout = 15.00
                mqttClient.allowUntrustCACertificate = true
                mqttClient.autoReconnect = true
                mqttClient.willMessage = CocoaMQTTMessage(topic: "/will", string: "dieout")
                mqttClient.delegate = self
               _ = mqttClient.connect()
            } else {
                
                UserManager.shared.isConnected = false
                delegate?.onMqttError(message: "Mqtt initialization error")
                status = .error
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions