emitter-io / csharp

Client library for emitter.io compatible with .Net, .Net MicroFramework and WinRT
http://emitter.io
Eclipse Public License 1.0
29 stars 21 forks source link

unable to connect mqtt over tls #15

Closed himadrinath closed 4 years ago

himadrinath commented 5 years ago

unable to connect using tls. in node project its working like this

require('emitter-io').connect( {host: 'myhost.com', port: 443 , secure: true });

passing secure options but in C# connection has 3 parameters broker, brokerPort, defaultkey

how can i connect?

Florimond commented 5 years ago

I suppose you installed the nugget and for some reason it wasn't updated.

The source code currently has these 4 constructors:

https://github.com/emitter-io/csharp/blob/2d68e4ba7926cfcd7c339f59d4fcc8bcb65720f0/Emitter/Emitter.cs#L65

You can either use the source code directly, or wait for us to look into this nugget update issue.

himadrinath commented 5 years ago

my version : 1.0.41

himadrinath commented 5 years ago

in this line using TLSv1_0 but mine is TLSv1_2 how can i change it..

https://github.com/emitter-io/csharp/blob/2d68e4ba7926cfcd7c339f59d4fcc8bcb65720f0/Emitter/Emitter.cs#L100

himadrinath commented 4 years ago

@Florimond after using source code directly getting this

Unhandled Exception: System.ArgumentException: Library compiled without SSL support
   at Emitter.MqttClient.Init(String brokerHostName, Int32 brokerPort, Boolean secure, X509Certificate caCert, X509Certificate clientCert, MqttSslProtocols sslProtocol, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback) in C:\Users\Himadri\Documents\Visual Studio 2017\Projects\Emitter_test\Emitter\MqttClient.cs:line 355
   at Emitter.MqttClient..ctor(String brokerHostName, Int32 brokerPort, Boolean secure, X509Certificate caCert, X509Certificate clientCert, MqttSslProtocols sslProtocol, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback) in C:\Users\Himadri\Documents\Visual Studio 2017\Projects\Emitter_test\Emitter\MqttClient.cs:line 319
   at Emitter.MqttClient..ctor(String brokerHostName, Int32 brokerPort, Boolean secure, MqttSslProtocols sslProtocol, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback) in C:\Users\Himadri\Documents\Visual Studio 2017\Projects\Emitter_test\Emitter\MqttClient.cs:line 300
   at Emitter.Connection..ctor(String defaultKey, String broker, Int32 brokerPort, Boolean secure) in C:\Users\Himadri\Documents\Visual Studio 2017\Projects\Emitter_test\Emitter\Emitter.cs:line 98
   at Emitter.Connection.Establish(String defaultKey, String broker, Int32 brokerPort, Boolean secure) in C:\Users\Himadri\Documents\Visual Studio 2017\Projects\Emitter_test\Emitter\Emitter.cs:line 176
Florimond commented 4 years ago

The Emitter project needs to be built with "SSL" and "FX".

image

Note: I don't have Visual Studio on hand right now to check this information, but I think this is right.

himadrinath commented 4 years ago

@Florimond if i use SSL getting error if i use Fx getting error On using SSL

Emitter_SSL_2019-09-23 185213

and using FX

Emitter_Fx_2019-09-23 185304

himadrinath commented 4 years ago

its fixed. with little bit of changes this repo helped https://github.com/mohaqeq/M2MqttDotnetCore