This time the M2Mqtt library has undergone some "important" changes in terms of new features and bug fixing. I have to admit that the improvements are mainly due to the people who use it and report me to add new features or bugs to fix. In addition to several issues reported on CodePlex, this time also Clemens Vasters, PM on Microsoft Azure, submitted some improvements to be applied in the context of SSL / TLS authentication. In fact, as already tweeted several weeks ago, Clemens used my library to run tests on the Reykjavik project (Device Gateway) presented at Build in 2014 and I can only be honored.
In this case, the improvement is closely related to the .Net Framework version, since it is the only version to support what has been added. In particular, the MqttClient class makes available other constructors which can provide the following callbacks :
For more information, you can refer to the official MSDN documentation.
In the case of more complex constructor (with both callbacks), an application example can be the following:
1: MqttClient client = new MqttClient("<server_name>", 8883, true, ValidateServerCertificate, SelectClientCertificate);
5: bool ValidateServerCertificate(object sender,
6: X509Certificate certificate,
7: X509Chain chain,
8: SslPolicyErrors sslpolicyerrors)
10: bool valid;
11: // check sslpolicyerrors and execute your certificate validation
14: return valid;
17: X509Certificate SelectClientCertificate(
18: Object sender,
19: string targetHost,
20: X509CertificateCollection localCertificates,
21: X509Certificate remoteCertificate,
22: string acceptableIssuers)
24: X509Certificate cert;
26: // choose client certificate from local store or creating new one
29: return cert;
Obsolete constructors and tracing
To try to simplify the creation of the client, the constructors who receive in input an IPAddress are now "marked" with the Obsolete attribute. In fact, all other constructors allow you to specify an IP address or a host name as input in string format; the constructor will check what type it is and in the case of host name to perform a conversion to IP address through DNS.
Regarding the tracing, some people have reported that in the Nuget version this functionality did not display the content of each message exchanged with broker but the type of the message; this was due to the fact that the Nuget library is compiled in Release mode but the trace messages were active in Debug. The current version provides tracing both in debug and release as it is related to the TRACE symbol (and no longer the DEBUG symbol) that is defined in both configurations. Obviously, the tracing is always tied to the definition of a TraceListener by the user.
The main fixed bugs were raised on CodePlex by some people. Following link with more information :
The library is evolving thanks to the community and very soon it will include MQTT 3.1.1 support that will be OASIS standard in few weeks. Another step is the license changed from L-GPL to Apache 2.0 !
As always you can fine new version on CodePlex, Nuget and Microsoft Code Gallery. I have also updated the GnatMQ broker (at version 0.9.1.0) and the M2Mqtt4CE project.
View this page in another language: