79648465

Date: 2025-06-02 09:21:16
Score: 1.5
Natty:
Report link

I have corrected the code (Thanks to @Larme) to solve the problem.

var state = mqtt.connect()
var subscribed = false
autoreleasepool {
  let runLoop = RunLoop.current
  while  runLoop.run(mode: .default, before: Date.distantFuture) {
    if mqtt.connState == .connected && !subscribed {
      mqtt.subscribe("test/#")
      subscribed = true
    }
  }

Before subscribing topics, it is important to wait until the connection is made. If the subscription is made immediately after the connect on a SSL connection, the broker will log an error:

2025-06-02T10:59:43: Client CocoaMQTT-88249 closed its connection.
2025-06-02T11:03:37: Client connection from 93.208.209.34 failed: error:0A00010B:SSL routines::wrong version number.

The above (resulting) error message might point to the wrong direction.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Larme
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: hjbflyer