emqx / CocoaMQTT

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

unacceptableProtocolVersion with EMQX Broker 3.0.0 #252

Closed blob8129 closed 5 years ago

blob8129 commented 5 years ago

I am trying to connect to EMQX Broker and getting

mqtt(_:didConnectAck:) unacceptableProtocolVersion
mqttDidDisconnect(_:withError:) Optional(Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer})

What could be the reason for this issue?

HJianBo commented 5 years ago

Hi @blob8129, The unacceptableProtocolVersion means that the Broker does not support the client specified MQTT protocol version (The CocoaMQTT used MQTT v3.1.1 ).

However, In my test, The CocoaMQTT can successfully connect to EMQX 3.0.0. Where did you get the EMQX 3.0.0?

mdrobny commented 5 years ago

Hi @HJianBo, thanks for response, I am with @blob8129 :)

We are using version 3.0.0 of EMQX broker https://github.com/emqx/emqx/releases/tag/v3.0.0 Downloaded from https://github.com/emqx/emqx/releases/download/v3.0.0/emqx-centos7-v3.0.0.zip

We are using authentication plugin to authenticate by username&password, did you test with credentials also?

HJianBo commented 5 years ago

I tested it with emqx_centos7_v3.0.0 by opening emqx_auth_username plugin. But it connecting successfully again. Does there some key miss??

The client and server is: Client: Example application of CocoaMQTT on the master branch Server: emqx-centos7-v3.0.0 with enable emqx_auth_username plugin (and added available user)

Can you provide a reproducible step?? Or, Capture the TCP data to check it Protocol Level field.

mdrobny commented 5 years ago

@HJianBo is protocol version defined here https://github.com/emqtt/CocoaMQTT/blob/master/Source/CocoaMQTTFrame.swift#L172 actually relevant?

HJianBo commented 5 years ago

Yes, but more accurately the client will send version info by using PROTOCL_LEVEL(4) and PROTOCL_MAGIC(mqtt).

mdrobny commented 5 years ago

@HJianBo we found the source of the problem 🎉

Removing mqtt.willMessage = CocoaMQTTWill(topic: "/will", message: "dieout") solved the issue because our user didn't have access to /will topic in ACLs.

I think ACLs validation of will topic was added in https://github.com/emqx/emqx/releases/tag/v3.0.0.

Of course I can also authorize our user to have publish access to /will topics (or any other topic for "last will and testament") and connection works without any problems!

Thanks for your great support :)

This issue can be closed


One more thing worth mentioning is that:

HJianBo commented 5 years ago

@mdrobny We finally resolved this problem, it caused by this PR: https://github.com/emqx/emqx/pull/2168