emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.57k stars 411 forks source link

How to connect to a broker on the network #554

Open GraceStangroome opened 9 months ago

GraceStangroome commented 9 months ago

Hello, I'm new to programming in Swift and networking, so please be gentle, but I'm really confused about how I actually get the Swift app to connect to a broker. I have the App working okay, and the broker works, and I essentially copied the example in the GitHub, but now what? What functions do I need to call, and how do I call them? My broker is a Raspberry Pi on the same network as the iPad.

I really appreciate any help you can provide.

leeway1208 commented 9 months ago

Hello. You can run the demo first and try to read the code. If you have the problem, you can list here. Thks~

GraceStangroome commented 8 months ago

I did that, and I am still struggling. It doesn't seem to be connecting to the broker at all. Any advice?

I think a bad connection isn't working correctly. When I try to use it and the broker is switched off (so cannot be working), the debug output says it connected and subscribed to a topic and published a message. When I look at the logs on the broker when it is switched on, it states a new connection from the iPad IP's, and then says Client disconnected due to protocol error.

leeway1208 commented 8 months ago

It seems like there is a problem with the broker settings?

GraceStangroome commented 8 months ago

I think that's fine because when I connect to the broker and publish from my Mac's terminal, everything works as expected, so it's definitely due to my Cocoa code