【发布时间】:2017-10-19 15:06:20
【问题描述】:
我正在 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)
任何帮助将不胜感激。我已经坚持了好几天了。
【问题讨论】:
-
mqtt 不支持 SSL 身份验证
-
你能详细说明你的意思吗?我正在使用此证书使用 MQTT.FX 使用 TLS 协议版本 1.2 成功连接。所以我对你想说的话感到困惑。
-
我相信我之前在 SO 上看到过这个问题。 OP 向该 API 的作者发送了电子邮件,发现该 API 不支持 SSL。我再也找不到那个帖子了,但如果我再次遇到它,我会链接它。这是大约 2 年前,所以也许他们现在支持它....
-
我发现这篇 2015 年 12 月的文章说他们现在支持它。也许那是在他们开始支持它之前? m2mqtt.wordpress.com/2015/12/06/324
标签: c# .net unity3d mqtt tls1.2