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

How to connect to Broker with TCP/TLS with port 8883? #492

Open
lygialiem opened this issue Nov 11, 2022 · 3 comments
Open

How to connect to Broker with TCP/TLS with port 8883? #492

lygialiem opened this issue Nov 11, 2022 · 3 comments

Comments

@lygialiem
Copy link

Hi team.

Currently, I setup MQTT connection like this:

let mqtt5 = CocoaMQTT5(clientID: "some_clientID", host: "54.179.31.220", port: 8883)
mqtt5.username = userName
mqtt5.password = password
mqtt5.allowUntrustCACertificate = true
mqtt5.enableSSL = true
mqtt5.connect()

but i always get this error: "Socket closed by remote peer". Did i miss something?

Thank you and Best Regard

@leeway1208
Copy link
Collaborator

Hi. Make sure your broker config is consistent with your writing code. Thanks.

@JaylinYu
Copy link
Member

JaylinYu commented Dec 1, 2022

please find the corresponding TLS/SSL log from broker side, this usually caused by malformed certificate or the version of SSL lib mismatch

@StarkGOD024
Copy link

I took several days to solve the set allowUntrustCACertificate = true, unable to connect the SSL problems, finally through the source code, found that need to implement the following method

// Optional ssl CocoaMQTTDelegate
func mqtt(_ mqtt: CocoaMQTT, didReceive trust: SecTrust, completionHandler: @escaping (Bool) -> Void) {
TRACE("trust: (trust)")
/// Validate the server certificate
///
/// Some custom validation...
///
/// if validatePassed {
/// completionHandler(true)
/// } else {
/// completionHandler(false)
/// }
completionHandler(true)
}

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

4 participants