Giter Club home page Giter Club logo

paho.mqttdotnet's Introduction

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

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);
}

paho.mqttdotnet's People

Contributors

xljiulang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.