Skip to content

Commit ebd65f9

Browse files
committed
Added example of publishing MQTT-SN over UDP with QoS -1
1 parent 1d6a297 commit ebd65f9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

examples/mqttsn_publish_minus_one.rb

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Send a MQTT-SN Publish packet at QoS -1
4+
# over UDP to a MQTT-SN server
5+
#
6+
7+
$:.unshift File.dirname(__FILE__)+'/../lib'
8+
9+
require 'rubygems'
10+
require 'socket'
11+
require 'mqtt'
12+
13+
14+
socket = UDPSocket.new
15+
socket.connect('localhost', MQTT::SN::DEFAULT_PORT)
16+
socket << MQTT::SN::Packet::Publish.new(
17+
:topic_id => 'TT',
18+
:topic_id_type => :short,
19+
:data => "The time is: #{Time.now}",
20+
:qos => -1
21+
)
22+
socket.close

0 commit comments

Comments
 (0)