I am trying to connect with mosquitto broker using m2mqtt c# client version 4.3.0 library via SSL/TLS. Below is the code I have tried
static void Main(string[] args)
{
// create client instance
MqttClient client = new MqttClient(IPAddress.Parse("127.0.0.1"), 8883, true,
new X509Certificate2("C:\\Users\\hp\\Desktop\\certificate\\ca.crt"),
new X509Certificate2("C:\\Users\\hp\\Desktop\\certificate\\client.crt"),
MqttSslProtocols.TLSv1_2);
// register to message received
client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
string clientId = "pahoSubscriber2";
client.Connect(clientId);
// subscribe to the topic "hello" with QoS 0
client.Subscribe(new string[] { "hello" }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE });
}
static void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
{
// handle message received
Console.WriteLine(e.Message);
}
but I am getting the exception
A call to SSPI failed, see inner exception.
and the inner exception says
the message received was unexpected or badly formatted
For information I can successfully connect with broker without SSL/TLS. Also using Paho Java client via both with or without SSL/TLS I can connect with the broker. This exception is happen only when I am trying to connect using m2mqtt C# client library via SSL/TLS. Any help or sample implementation will be appriciated.