使用M2MQTT在VB.Net中的MQTT订户

时间:2017-09-29 14:47:09

标签: vb.net

我正在尝试使MQTT订阅者在VB.NET中工作。我正在使用M2MQTT来达到这个目的。以下是代码。

Sub client_MqttMsgPublishReceived(sender As Object, e As 
                                    MqttMsgPublishEventArgs)
    MsgBox(e.Message())
    MsgBox(e.Message)

End Sub

测试代码

  Dim k As New MqttClient("broker.hivemq.com", 1883, False, New 
                                            X509Certificate)
    MsgBox(k.Settings.Port())

    Dim clientId As String = Guid.NewGuid().ToString()

    AddHandler k.MqttMsgPublishReceived, AddressOf client_MqttMsgPublishReceived
    k.Connect(clientId, "test", "test")

    k.Subscribe(New String() {"start"}, Encoding.UTF8.GetBytes(MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE))

    MsgBox(k.IsConnected())

因此IsConnected()在此代码中返回false。我做错了什么?

1 个答案:

答案 0 :(得分:1)

该项目可能有用。 它包含库M2Mqtt的所有功能

https://github.com/bassouma21001/MQTTBasic