forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
28 lines (20 loc) · 748 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var MqttServer = require("vertx-mqtt-js/mqtt_server");
var options = {
"port" : 1883,
"host" : "0.0.0.0"
};
var server = MqttServer.create(vertx, options);
server.endpointHandler(function (endpoint) {
console.log("connected client " + endpoint.clientIdentifier());
endpoint.publishHandler(function (message) {
console.log("Just received message on [" + message.topicName() + "] payload [" + message.payload() + "] with QoS [" + message.qosLevel() + "]");
});
endpoint.accept(false);
});
server.listen(function (ar, ar_err) {
if (ar_err == null) {
console.log("MQTT server started and listening on port " + server.actualPort());
} else {
console.error("MQTT server error on start" + ar_err.getMessage());
}
});