doxdici
doxdici

Reputation: 47

MQTTNET connection

I have written this application to use mqttnet library but connection failed. How is it possible to get mqttnet with a trace? Do you notice something wrong with the connection? Here my code

            var mqttClient = new MqttFactory(new MQTTnet.Diagnostics.MqttNetLogger("MyCustomId")).CreateMqttClient();
        var caCert = X509Certificate.CreateFromCertFile("C:\\ca.crt");
        var clientCert = new X509Certificate2("C:\\certificate.pfx", "uno");

        var options = new MqttClientOptionsBuilder()
           .WithCredentials("ut", "pwd")
           .WithTcpServer("mydns", 8883)
            .WithTls(new MqttClientOptionsBuilderTlsParameters
            {
                UseTls = true,
                SslProtocol = System.Security.Authentication.SslProtocols.Tls13,
                Certificates = new List<X509Certificate>()
                    {
                        caCert, clientCert
                    },
                    CertificateValidationCallback = (X509Certificate x, X509Chain y, SslPolicyErrors z, IMqttClientOptions o) =>
                    {
                        return true;
                    }
            })
            .Build();
        MQTTnet.Client.Connecting.MqttClientAuthenticateResult r=await mqttClient.ConnectAsync(options, CancellationToken.None);

Thank you any help would be appreciated

Upvotes: 2

Views: 650

Answers (1)

doxdici
doxdici

Reputation: 47

I have replaced "CreateMqttClient" with "CreateManagedMqttClient" and modified the subsequent part of the code and all has worked

Upvotes: 1

Related Questions