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

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

Open
steveSarsawa-git opened this issue Jul 22, 2024 · 0 comments

Comments

@steveSarsawa-git
Copy link

steveSarsawa-git commented Jul 22, 2024

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
            }
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

1 participant