C# - Unity3d MQTT - ArgumentException:在没有 SSL 支持的情况下编译的库



>伙计们!我一直在使用 Unity 以便使用 MQTT 协议将用于Microsoft Hololens 的 Unity 应用程序连接到服务器。我在Github上找到了一个名为Unity3d MQTT的项目,它似乎符合我的目的。

然后,我在Unity中制作了一个名为MQTTListener的C#脚本。它写如下:

using System.Security.Cryptography.X509Certificates;
using UnityEngine;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
public class MQTTListener : MonoBehaviour{
private const int port = 8883;
private readonly string deviceId = "<deviceId>";
private readonly string hubAddress = "<hubAddress>";
private readonly string password = "<sasToken>";
private MqttClient client;
private string username;
public TextAsset certificate;
void Start(){
// Forming a certificate based on a TextAsset
var cert = new X509Certificate();
cert.Import(this.certificate.bytes);
// Making a new MQTT client with the formed certificate
this.client = new MqttClient(
brokerHostName: this.hubAddress,
brokerPort: MQTTListener.port,
secure: true,
caCert: cert
);
// Initializing MQTT listener events
this.client.MqttMsgPublishReceived += Client_MqttMsgPublishReceived;
this.username = "/" + deviceId;
// Establish a connection to the target device
this.client.Connect(
clientId: this.deviceId,
username: this.username,
password: this.password
);
var hubTopicSubscribe = "/devices/" + this.deviceId + "/messages/devicebound/#";
this.client.Subscribe(
new string[]{ hubTopicSubscribe },
new byte[]{ MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE } // QoS = Quality of Service
);
}
private void Client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e){
Debug.Log("Received: " + System.Text.Encoding.UTF8.GetString(e.Message));
}
void Update(){

}
}

代码编译正常,但后来我遇到了以下问题:

参数异常:在没有 SSL 支持的情况下编译的库

uPLibrary.Networking.M2Mqtt.MqttClient.Init (System.String brokerHostName, System.Net.IPAddress brokerIpAddress, Int32 代理端口, 布尔安全, System.Security.Cryptography.X509Certificates.X509Certificate caCert)

(at Assets/MQTT/scripts/MqttClient.cs:320) uPLibrary.Networking.M2Mqtt.MqttClient..ctor (System.String brokerHostName, Int32 brokerPort, Boolean secure, System.Security.Cryptography.X509Certificates.X509Certificate caCert) (at Assets/MQTT/scripts/MqttClient.cs:268)MQTTListener.Start () (at Assets/HoloProject/Scripts/MQTTListener.cs:26)

看起来很简单,但是实际上我如何编译具有SSL支持的库(无论它在哪里)?

MqttClient 有 6 个 surchage,包括 clientCert 和 sslProtocol (ex:MqttSslProtocols.TLSv1_1)。顺便说一句,我不明白同时使用 SAS 令牌和 509 证书身份验证的意义