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
Disconnect: The operation couldn’t be completed. Socket is not connected
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
}
I'm facing issue, like whenever i tried to established connection through Mobile data.
MQTT getting disconnectedautomatically, and if i tried to reconnect getting below error. InandroidandReact native iOS Appis working fine. But issue i'm facing only inSwift iOS. I've tried all the possible ways, withenable ssl, withoutssl.allowUntrustedCertificatesand so on. But nothing is helping here