【问题标题】:Where to get HELLO WORLD for .net with M2mQTT哪里可以使用 M2mQTT 获得适用于 .net 的 HELLO WORLD
【发布时间】:2015-12-21 04:24:35
【问题描述】:

开始在 .net 环境中使用 MQTT,作为一个新手,遇到一些问题,例如无法在发布者和订阅者之间进行通信。从 eclipse.org 我得到下面的语法

// SUBSCRIBER
...

// create client instance
MqttClient client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS));

// register to message received
client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

string clientId = Guid.NewGuid().ToString();
client.Connect(clientId);

// subscribe to the topic "/home/temperature" with QoS 2
client.Subscribe(new string[] { "/home/temperature" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });

...


static void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
{
// handle message received
}

// PUBLISHER
... 

// create client instance
MqttClient client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS)); 

string clientId = Guid.NewGuid().ToString();
client.Connect(clientId); 

string strValue = Convert.ToString(value); 

// publish a message on "/home/temperature" topic with QoS 2
client.Publish("/home/temperature", Encoding.UTF8.GetBytes(strValue), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE); 

...

在上面的语法中,我是如何获得 MQTT_BROKER_ADDRESS 的,到目前为止,我从 hivemq 等其他文档中了解到我需要部署它。有没有经纪人可以使用它?我需要 MQTT for .net 上的 HELLO WORLD 类型的项目。 其中有发布者、订阅者和代理。

【问题讨论】:

    标签: c# .net eclipse mqtt mosquitto


    【解决方案1】:

    mqtt.org 是从 MQTT 开始寻求帮助的好地方,在它的 wiki 部分中,它有一组面向公众的代理,可用于入门。

    https://github.com/mqtt/mqtt.github.io/wiki/public_brokers

    【讨论】:

    • hardillb,谢谢你的回复,想知道​​为什么我的服务器没有用我的客户端回复我。谢谢
    • 你在这个问题中问的不是这个
    • hardillb,请告诉我一些指导方针,为什么我的服务器 gnatmq 没有响应我。
    【解决方案2】:

    只需替换

    MqttClient client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS)); 
    

    MqttClient client = new MqttClient("broker.mqtt-dashboard.com");
    

    其中broker.mqtt-dashboard.com 是 HiveMQ 提供的用于测试目的的 MQTT 代理的地址。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      相关资源
      最近更新 更多