Exception during AWS connection #2012
Closed
gabrielvictorafreitas
started this conversation in
General
Replies: 2 comments 8 replies
-
This error happens when you try to connect to an endpoint without TLS enabled, make sure you are using the right I double checked with the code below and I'm able to connect to IoTCore in AWS var factory = new MqttFactory();
var mqttClient = factory.CreateMqttClient();
string brokerAddress = "******-ats.iot.us-west-1.amazonaws.com";
X509Certificate2 cert = X509Certificate2.CreateFromPemFile("cert.pem", "private.key");
IEnumerable<X509Certificate2> certs = new List<X509Certificate2>
{
// see https://github.com/dotnet/runtime/issues/45680#issuecomment-739912495
new X509Certificate2(cert.Export(X509ContentType.Pkcs12))
};
var mqttClientOptions = new MqttClientOptionsBuilder()
.WithTcpServer(brokerAddress)
.WithClientId("basicPubsub")
.WithTlsOptions(o => o.WithClientCertificates(certs))
.Build();
var response = await mqttClient.ConnectAsync(mqttClientOptions);
Console.WriteLine(response.ResultCode); Some comments from your code:
|
Beta Was this translation helpful? Give feedback.
8 replies
-
@rido-min Thank you a lot! Now it's working! May main issue was this part: And I followed your comments! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone!
I'm trying to connect into an AWS Broker using .net6 and MqttNet 4.3.6.1152 and i'm receiving this exception:
It's good to mention that I'm testing on WSL Ubuntu 20.04 and production server is a Linux Ubuntu 20.04!
Exception has occurred: CLR/MQTTnet.Exceptions.MqttCommunicationException An unhandled exception of type 'MQTTnet.Exceptions.MqttCommunicationException' occurred in System.Private.CoreLib.dll: ' Received an unexpected EOF or 0 bytes from the transport stream.' Inner exceptions found, see $exception in variables window for more details. Innermost exception System.IO.IOException : Received an unexpected EOF or 0 bytes from the transport stream. at System.Net.Security.SslStream.<<FillHandshakeBufferAsync>g__InternalFillHandshakeBufferAsync|189_0>d
1.MoveNext()at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable
1.ConfiguredValueTaskAwaiter.GetResult() at System.Net.Security.SslStream.<ReceiveBlobAsync>d__176
1.MoveNext()at System.Threading.Tasks.ValueTask
1.get_Result() at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable
1.ConfiguredValueTaskAwaiter.GetResult()at System.Net.Security.SslStream.d__175
1.MoveNext() at MQTTnet.Implementations.MqttTcpChannel.<ConnectAsync>d__17.MoveNext() at MQTTnet.Implementations.MqttTcpChannel.<ConnectAsync>d__17.MoveNext() at MQTTnet.Adapter.MqttChannelAdapter.<>c__DisplayClass30_0.<<ConnectAsync>b__1>d.MoveNext() at MQTTnet.Adapter.MqttChannelAdapter.<ConnectAsync>d__30.MoveNext()
This is my code:
`private async Task StartMqttServer(CancellationToken cancellationToken)
{
`
Any help please?
Beta Was this translation helpful? Give feedback.
All reactions