尝试连接到 unity3d 中启用 TLS 的代理时 MQTT 超时

MQTT Timeout when trying to connect to TLS enabled broker in unity3d

我正在 Unity 中构建 AR 应用程序,我需要连接到启用了 TLS 协议的 MQTT 代理。我能够成功连接到未启用 TLS 的 MQTT 代理(统一),并且我可以使用管理员通过此程序给我的证书 http://www.mqttfx.org/ 成功连接到启用 TLS 的代理。但是,当我尝试使用 Unity 中用于 c# 的 m2mqtt 库连接到启用 TLS 的服务器时,我收到超时异常并且从未收到代理的响应。这是我用来测试连接的代码。我只是想建立一个成功的连接然后断开连接。

X509Certificate certificate = X509Certificate.CreateFromCertFile("filePath");

// Connect to this broker address at port 1883 with tls enabled 
client = new MqttClient(brokerAddress, port, true, certificate);

// Generate a client id
string clientId = Guid.NewGuid().ToString(); 

// Connect to the client with credentials
byte code = client.Connect(clientId, username, password;

// Disconnect       
client.Disconnect ();

连接期间发生此异常:

MqttCommunicationException: An application exception has occurred.
uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive (System.Byte[] msgBytes, Int32 timeout) (at Assets/MQTT/scripts/MqttClient.cs:953)
uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive (uPLibrary.Networking.M2Mqtt.Messages.MqttMsgBase msg, Int32 timeout) (at Assets/MQTT/scripts/MqttClient.cs:976)
uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive (uPLibrary.Networking.M2Mqtt.Messages.MqttMsgBase msg) (at Assets/MQTT/scripts/MqttClient.cs:964)
uPLibrary.Networking.M2Mqtt.MqttClient.Connect (System.String clientId, System.String username, System.String password, Boolean willRetain, Byte willQosLevel, Boolean willFlag, System.String willTopic, System.String willMessage, Boolean cleanSession, UInt16 keepAlivePeriod) (at Assets/MQTT/scripts/MqttClient.cs:456)
uPLibrary.Networking.M2Mqtt.MqttClient.Connect (System.String clientId, System.String username, System.String password, Boolean cleanSession, UInt16 keepAlivePeriod) (at Assets/MQTT/scripts/MqttClient.cs:395)
ConnectionManager.connectToMQTTBroker () (at Assets/Scripts/ConnectionManager.cs:55)

如有任何帮助,我们将不胜感激。我已经坚持了好几天了。

M2Mqtt 不支持 TLS_V2 ,因为我们不能统一使用证书。这是由于 .Net FrameWork 版本支持。对于证书,我们使用 TLSV_2 .Net 4 及更高版本支持的 QOS 级别进行连接,但 Unity 仅支持 .Net 3.5 版本。