Mqtt Client TLS 1.3

Unable to implement tls 1.3 in c# using MQTTnet client.

Broker : Hivemq

Can anyone help with implementation in c#?

Thanks
Rahul

Hi @Rahul,

so I think the solution is the MqttClientOptionsBuilder, there you can set the TLS version:

var mqttFactory = new MqttFactory();

        using (var mqttClient = mqttFactory.CreateMqttClient())
        {
            var mqttClientOptions = new MqttClientOptionsBuilder().WithTcpServer("test.mosquitto.org", 8883)
                .WithTls(
                    o =>
                    {
                        o.SslProtocol = SslProtocols.Tls13; //set tls version
                    })
                .Build();

            // In MQTTv5 the response contains much more information.
            var response = await mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);

            Console.WriteLine("The MQTT client is connected.");

            response.DumpToConsole();
        }

Greetings,
Michael from the HiveMQ team