dotnet / dotnet/MQTTnet

My client receive Disconnected when I set mqqtv5 to connect emqx bloker

Open
#1,912 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
C#
Stars
5.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

## I did following tests

* mqttx desktop client (use mqttv5) to try the emqx bloker that was ok.
* MQTTNET client
If I remove mqttv5 option(swith to ```default ProtocolVersio```) , the connect worked fine.
If I change bloker to mosquito bloker(use mqttv5), everything is ok.
If I use mqttv5 to connect to emqx bloker,I recive Disconnect with reason code ( ProtocolError)

Here is my Code
``` C#

_mqttClientOptions = new MqttClientOptionsBuilder()
.WithProtocolVersion(MqttProtocolVersion.V500)
.WithCredentials("my_user", "testpsw")
.WithTcpServer("exmq.xxx.cn", 1883).Build();

_client.ApplicationMessageReceivedAsync += ProcessEventAsync;
_client.DisconnectedAsync += DisconnectedAsync;

_ = Task.Run(
async () =>
{
// User proper cancellation and no while(true).
while (true)
{
try
{

// This code will also do the very first connect! So no call to _ConnectAsync_ is required in the first place.
if (await _client.TryPingAsync()) continue;
_logger.LogInformation("Try to connect the blocker");
await _client.ConnectAsync(_mqttClientOptions, CancellationToken.None);

SubscribeHandlers(_abpMqttEventBusOptions.Handlers);
_logger.LogInformation("Connected");
}
catch (Exception e)
{
_logger.LogException(e);
}
finally
{
// Check the connection state every 5 seconds and perform a reconnect if required.
await Task.Delay(TimeSpan.FromSeconds(5));
}
}
});
}

private Task DisconnectedAsync(MqttClientDisconnectedEventArgs arg)
{
_logger.LogError(arg.Exception, $"{arg.Reason.ToString()}({(int) arg.Reason})");
return Task.CompletedTask;
}
```

2024-01-19 14:25:18[INF][MqttEventBus] - Connected
2024-01-19 14:25:18[ERR][MqttEventBus] - ProtocolError(130)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.