forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.rb
More file actions
28 lines (20 loc) · 657 Bytes
/
server.rb
File metadata and controls
28 lines (20 loc) · 657 Bytes
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
require 'vertx-mqtt/mqtt_server'
options = {
'port' => 1883,
'host' => "0.0.0.0"
}
server = VertxMqtt::MqttServer.create($vertx, options)
server.endpoint_handler() { |endpoint|
puts "connected client #{endpoint.client_identifier()}"
endpoint.publish_handler() { |message|
puts "Just received message on [#{message.topic_name()}] payload [#{message.payload()}] with QoS [#{message.qos_level()}]"
}
endpoint.accept(false)
}
server.listen() { |ar_err,ar|
if (ar_err == nil)
puts "MQTT server started and listening on port #{server.actual_port()}"
else
STDERR.puts "MQTT server error on start#{ar_err.get_message()}"
end
}