Giter Club home page Giter Club logo

mqtt's Introduction

Mqtt Demo(待补齐...)

快速搭建

安装node、npm

国内:http://nodejs.cn/download/
国外:https://nodejs.org/en/download/

项目初始化

$ cd mqtt
$ npm i

启动webServer,监听8080端口

$ npm run server 

启动mqttServer,监听1884端口

$ npm run mqttServer 

打开浏览器,输入localhost:8080,可以看到服务正常启动。

MqttClient

使用paho mqtt client,作为客户端mqtt-sdk API文档:http://www.eclipse.org/paho/files/jsdoc/Paho.MQTT.Message.html

在paho-mqtt-client基础上做了一点封装

实例化

new MqttClient({
    id: "xxx", // clientName
    host: location.hostname, // wss连接host
    port: +1884, // wss连接端口
    onConnect() { // 连接成功回调
       // do something
    },
    onConnectionLost() { // 连接断开回调
       // do something
    },
    onMessageArrived() { // 消息送达回调
       // do something
    }
})

属性

@property {array} topicList 客户端订阅的主题列表
@property {object} client 已经实例化的mqtt客户端

方法

@method {function} send 客户端发送信息
@method {function} subscribe 客户端订阅主题

MqttServer

使用node-mosca搭建mqtt服务端 API文档:https://github.com/mcollina/mosca/wiki

mqtt's People

Contributors

lou1swu 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.