Click here to Skip to main content
15,615,280 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have a connection problem whit client M2Mqtt. I try to connect to my iot things in this way:

But message of Connax not arrive.
The strange is that a pyton script setting whit the same field, connect correctly, and the same for awsIotClient
Can you help me please
Thank's a lot

What I have tried:

var caCert = X509Certificate.CreateFromCertFile(@"C:\DiscoD\MqttRuleDefault\root.crt");

var clientCert = new X509Certificate2(@"C:\DiscoD\MqttRuleDefault\xxxx-certificate.crt");

string path = @"C:\DiscoD\MqttRuleDefault\xxxxx-private.pem.key";
string privateKey = this.GetStringFromFile(path);
byte[] keyBuffer = Helpers.GetBytesFromPEM(privateKey, PemStringType.RsaPrivateKey);

RSACryptoServiceProvider prov = Crypto.DecodeRsaPrivateKey(keyBuffer);
clientCert.PrivateKey = prov;



RemoteCertificateValidationCallback cb = new RemoteCertificateValidationCallback(Pippo);
LocalCertificateSelectionCallback lcb = new LocalCertificateSelectionCallback(Pippo1);

var client = new MqttClient("", 443, true, caCert, clientCert, MqttSslProtocols.TLSv1_2, cb, lcb, new List<string>() { "x-amzn-mqtt-ca" });

string clientId = Guid.NewGuid().ToString();

client.ConnectionClosed += Client_ConnectionClosed;
client.MqttMsgPublished += Client_MqttMsgPublished;
client.MqttMsgPublishReceived += Client_MqttMsgPublishReceived;
client.MqttMsgSubscribed += Client_MqttMsgSubscribed;
client.MqttMsgUnsubscribed += Client_MqttMsgUnsubscribed;

Updated 8-Apr-21 5:18am
Member 14524258 9-Apr-21 5:39am    
IThink to be solved, connect to 8883 port with client certificate exported to pfx with private key

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900