M2Mqtt is a MQTT client available for all .Net platform
Introduction
M2Mqtt is a MQTT client available for all .Net platform (.Net Framework, .Net Compact Framework and .Net Micro Framework) for Internet of Things and M2M communication.
MQTT, short for Message Queue Telemetry Transport, is a light weight messaging protocol that enables embedded devices with limited resources to perform asynchronous communication on a constrained network.
MQTT protocol is based on publish/subscribe pattern so that a client can subscribe to one or more topics and receive messages that other clients publish on these topics.
This sample is a library contains an MQTT client that you can use to connect to any MQTT broker. It is developed in C# language and works on all the following .Net platforms :
- .Net Framework (up to 4.5)
- .Net Compact Framework 3.5 & 3.9 (for Windows Embedded Compact 7 / 2013)
- .Net Micro Framework 4.2 & 4.3
- Mono (for Linux O.S.)
It can be used on Windows O.S, Windows Embedded Compact 7 / 2013 and Linux O.S. (thanks to Mono Project).
Official web site on CodePlex : https://m2mqtt.codeplex.com/
Building the Sample
The library is available for the following solution and project files :
- M2MqttVS2012.sln : solution for Visual Studio 2012 that contains projects file for .Net Framework, .Net Compact Framework 3.9, .Net Micro Framework 4.2 and .Net Micro Framework 4.3;
- M2MqttVS2010.sln : solution for Visual Studio 2010 that contains projects file for .Net Framework and .Net Micro Framework 4.2;
- M2MqttVS2008.sln : solution for Visual Studio 2008 that contains project file for .Net Compact Framework 3.5;
- M2MqttMono.sln : solution for MonoDevelop for building project under Linux O.S. with Mono Project;
In this sample there is only the Visual Studio 2012 solution but on the CodePlex web site https://m2mqtt.codeplex.com/ all other versions are available.
To build sample based on .Net Micro Framework (4.2 and 4.3) you need to download .Net Micro Framework SDK from the official CodePlex web site : https://netmf.codeplex.com/
To build sample based on .Net Compact Framework 3.9 you need to download Application Builder for Windows Embedded Compact 2013 from here : http://www.microsoft.com/en-us/download/details.aspx?id=38819
Description
The M2Mqtt library provides a main class MqttClient that represents the MQTT client to connect to a broker. You can connect to the broker providing its IP address or host name and optionally some parameters related to MQTT protocol.
After connecting to the broker you can use Publish() method to publish a message to a topic and Subscribe() method to subscribe to a topic and receive message published on it. The MqttClient class is events based so that you receive an event when a message is published to a topic you subscribed to. You can receive event when a message publishing is complete, you have subscribed or unsubscribed to a topic.
Following an example of client subscriber to a topic :
...
// 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
}
Following an example of client publisher to a topic :
...
// 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);
M2Mqtt is a MQTT client available for all .Net platform的更多相关文章
- python mqtt client publish操作
使用Python库paho.mqtt.client 模拟mqtt client 连接broker,publish topic. #-*-coding:utf-8-*- import paho.mqtt ...
- mqtt client python example
This is a simple example showing how to use the [Paho MQTT Python client](https://eclipse.org/paho/c ...
- go ---MQTT client
Paho GO Client 语言 GO 协议 EPL AND EDL 官网地址 http://www.eclipse.org/paho/ API类型 Asynchronous 描述 Paho ...
- mqtt client api: 阻塞API
fusesource版本:mqtt-client-1.11.jar下载地址:https://github.com/fusesource/mqtt-client fusesource提供三种mqtt c ...
- MQTT Client library for C (MQTT客户端C语言库-paho)
原文:http://www.eclipse.org/paho/files/mqttdoc/MQTTClient/html/index.html 来自我的CSDN博客 最近在使用Paho的MQTT客 ...
- MQTT Server搭建(apache-apollo)和MQtt Client搭建
目标 本文就MQTT server和client搭建做以下总结,方便测试及开发使用,能基于MQTT软件发送和接收消息. 介绍 MQTT是基于tcp的消息发送,目前JAVA方面有两种实现,分别是mqtt ...
- php mqtt client
<?php /* phpMQTT */ class phpMQTT { private $socket; /* holds the socket */ private $msgid = 1; / ...
- Asynchronous MQTT client library for C (MQTT异步客户端C语言库-paho)
原文:http://www.eclipse.org/paho/files/mqttdoc/MQTTAsync/html/index.html MQTT异步客户端C语言库 用于C的异步 MQTT 客 ...
- 一套权威的 MQTT Client 库
主流的语言都支持,可链接到 github ,亲测golang client 简单好用 http://www.eclipse.org/paho/downloads.php
随机推荐
- PHP 二维数组根据某个字段排序 复制代码 array_multisort
//二维数组,按照里面的age从大到小降序,代码如下 <?php header('Content-Type:text/html;Charset=utf-8'); $arrUsers = arra ...
- BZOJ 1449: [JSOI2009]球队收益 最小费用最大流 网络流
https://www.lydsy.com/JudgeOnline/problem.php?id=1449 给每条路加上一个权值,每条路的费用是这条路的流量*权值,求最大流的最小费用. 每次spfa记 ...
- 程序逻辑问题---Writeup
原题地址:http://ctf5.shiyanbar.com/web/5/index.php 打开后是一处登陆界面 右键查看源代码 发现有一处txt文件 很明显就是程序的源代码 可以看到其中一句 $s ...
- hdu 4025 Equation of XOR 状态压缩
思路: 设: 方程为 1*x1 ^ 1*x2 ^ 0*x3 = 0; 0*x1 ^ 1*x2 ^ 1*x3 = 0; 1*x1 ^ 0*x2 ^ 0*x3 = 0 把每一列压缩成一个64位整数,因为x ...
- win7 64位安装pywin32
先安装pywin32-218.win-amd64-py3.4.exe文件: 安装完成后,用CMD管理员模式进入\Python34\Scripts\目录 输入pywin32_postinstall.py ...
- tyvj:1520 树的直径 spfa/树的直径
tyvj:1520 树的直径 Time Limit: 1 Sec Memory Limit: 131072KiBSubmit: 9619 Solved: 3287 题目连接 http://www. ...
- 监听当点击微信等app的返回按钮或者浏览器的上一页或后退按钮的事件
在实际的应用中,我们常常需要实现在移动app和浏览器中点击返回.后退.上一页等按钮实现自己的关闭页面.调整到指定页面或执行一些其它操作的 需求,那在代码中怎样监听当点击微信.支付宝.百度糯米.百度钱包 ...
- jquery常用写法简单记录
好久不写东西了......话不多说,主要记录一下,最近做的项目中用到的js的记录(虽然特别特别简单) 一 jquery常用写法记录 jQuery(this).addClass("select ...
- 图解PCB布线数字地、模拟地、电源地,单点接地抗干扰!
我们在进行pcb布线时总会面临一块板上有两种.三种地的情况,傻瓜式的做法当然是不管三七二十一,只要是地 就整块敷铜了.这种对于低速板或者对干扰不敏感的板子来讲还是没问题的,否则可能导致板子就没法正常工 ...
- Andriod 环境配置以及第一个Android Application Project
Android 入门学习心得-----------------环境配置以及一些文件的理解 Android 开发似乎早已经开始疯狂起来了,今天,也开始学习了Android的开发.首先,必须要面 ...