'Connect to AWS MQTT

Trying to connect to AWS IOT device from C# by using M2MQTT library :

public void connect()
        {

            const string IotEndpoint =  "a3cnel9bxxxxx-ats.iot.eu-central-1.amazonaws.com";
            const int BrokerPort = 8883;

            const string Topic = "topic_1";
            

            X509Certificate clientCert = X509Certificate2.CreateFromCertFile("C:\\cpp_test\\certs\\pi4\\certificate.pem.crt");
            X509Certificate caCert = X509Certificate.CreateFromCertFile("C:\\cpp_test\\certs\\Amazon-root-CA-1.pem");

            
            MqttClient client = new MqttClient(IotEndpoint, BrokerPort, true, caCert, clientCert, MqttSslProtocols.TLSv1_2);
            
            String message = "Test message";
            string clientId = Guid.NewGuid().ToString();

            
            
        try
        {
            client.Connect(clientId);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            if (ex.InnerException != null)

                MessageBox.Show("Inner exception: {0}", ex.InnerException.Message);

        }
            
            client.Publish(Topic, Encoding.UTF8.GetBytes(message));

        }

Got exception:

 Received an unexpected EOF or 0 bytes from the transport stream.

What might be wrong? Where is starting point of problem solving?



Solution 1:[1]

Getting no data is often a result of the SSL handshake failing or protocols not being supported, verify the certificates and protocols are correct.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1