Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xljiulang/paho.mqttdotnet
A .Net wrapper for eclipse/paho.mqtt.c
https://github.com/xljiulang/paho.mqttdotnet
mqtt mqtt-client paho
Last synced: 14 days ago
JSON representation
A .Net wrapper for eclipse/paho.mqtt.c
- Host: GitHub
- URL: https://github.com/xljiulang/paho.mqttdotnet
- Owner: xljiulang
- Created: 2017-06-13T02:50:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-15T15:59:28.000Z (almost 7 years ago)
- Last Synced: 2024-10-03T12:26:42.594Z (about 1 month ago)
- Topics: mqtt, mqtt-client, paho
- Language: C#
- Homepage:
- Size: 250 KB
- Stars: 43
- Watchers: 9
- Forks: 15
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Paho.MqttDonet
A .Net wrapper for eclipse/paho.mqtt.c, support async/await asynchronous## Dependencies
* eclipse/paho.mqtt.c
* vs2012/.net framework 4.0 or later
* Visual C++ Redistributable 2015## Support
* Asp.net / WCF
* WinForm / WPF
* Console / Service## Demo
```c#
async static Task DemoAsync()
{
// Trace
MqttClient.SetTraceLevel(MqttTraceLevels.Protocol);
MqttClient.SetTraceCallback((level, message) => Console.WriteLine(message));// Listening message
var client = new MqttClient("mqtt://127.0.0.1", "clientId");
client.OnMessageArrived += (sender, topic, message) =>
{
Console.WriteLine("got message " + message);
var msg = new MqttMessage(message.QoS, "from MqttDotnet client");
var mqClient = sender as MqttClient;
mqClient.SendMessageAsync(topic, msg);
};// Process Connection Lost
client.OnConnectionLost += async (sender) =>
{
var mqClient = sender as MqttClient;
while (mqClient.IsConnected == false)
{
await mqClient.ReConnectAsync();
}
await client.SubscribeAsync("mqtt/dotnet/xljiulang", MqttQoS.ExactlyOnce);
};// Connect & subscribe
await client.ConnectAsync(new ConnectOption
{
Username = "MqttDotnet",
Password = "123456",
});
await client.SubscribeAsync("mqtt/dotnet/xljiulang", MqttQoS.ExactlyOnce);
}
```