dotnet / MQTTnet

MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
MIT License
4.51k stars 1.07k forks source link

Doesn't this Client support my own mqtt morker? #787

Closed taroyutao closed 4 years ago

taroyutao commented 5 years ago

Describe your question

I user MQTT.fx with username、password、port and broker url connect my own mqtt broker,everything works fine.

But when I use this Client with the same infomation, it doesn't work.

Code: string ServerUrl = "***.iot-as-mqtt.cn-shanghai.aliyuncs.com"; string UserName = "**"; string Password = "**"; string clientId = "**"; var options = new MqttClientOptionsBuilder() .WithClientId(clientId) .WithTcpServer(ServerUrl,1883) .WithCredentials(UserName, Password) .WithTls() .WithCleanSession() .Build();

        mqttClient.ConnectAsync(options).GetAwaiter().GetResult();

The error info: MQTTnet.Adapter.MqttConnectingFailedException HResult=0x80131500 Message=Connecting with MQTT server failed (ClientIdentifierNotValid). Source=MQTTnet StackTrace: at MQTTnet.Client.MqttClient.d40.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MQTTnet.Client.MqttClient.d33.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at MQTTnet.Client.MqttClient.d__33.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at ConsoleApp1.Program.Main(String[] args) in C:\Users\Administrator\source\repos\MQTTDemo\ConsoleApp1\Program.cs:line 30

Which project is your question related to?

Can you give me some advices, thanks.

SeppPenner commented 5 years ago

What is your client id? I mean, the error says: ClientIdentifierNotValid. Maybe something is wrong there or you are using some not supported char maybe?

SeppPenner commented 4 years ago

Another hint might be that you're trying to use SSL on port 1883? I don't know if this is intended, but normally 8883 is the SSL port for MQTT over SSL...

As this issue is open quite long and you didn't answer my question (We need more information to help you out), I will close this issue now. Just write another message here if this still occurs and (if possible provide more information to us).

0xn3bs commented 4 years ago

@SeppPenner I'm having the same issue as the user above, we're both connecting to the same broker it seems.

The clientIds for aliyuncs brokers are a bit long, here's an example: 123456|securemode=3,signmethod=hmacsha1,timestamp=1598679202|

Using the same settings in MQTT.fx it works fine.

0xn3bs commented 4 years ago

@SeppPenner disregard, after further investigation of the CONNECT packet between MQTT.fx and what was being generated by MQTTnet I noticed the KeepAlive period was the only thing different.

aliyuncs has a requirement that the KeepAlive period is at least 30 seconds. If it's any less it will return an InvalidClient error.

Keep this ticket closed, thank you.