OLD | NEW |
1 import 'dart:fletch'; | 1 import 'dart:dartino'; |
2 import 'package:mqtt/mqtt.dart'; | 2 import 'package:mqtt/mqtt.dart'; |
3 | 3 |
4 // Sample code for publishing messages. | 4 // Sample code for publishing messages. |
5 // | 5 // |
6 // For an end-to-end sample, first run subscribe-sample.dart, and then start | 6 // For an end-to-end sample, first run subscribe-sample.dart, and then start |
7 // this program next to see the communication between the two. Note that this | 7 // this program next to see the communication between the two. Note that this |
8 // program has to be started in a second session, e.g. `fletch start | 8 // program has to be started in a second session, e.g. `dartino start |
9 // publish-sample.dart in session 2'. | 9 // publish-sample.dart in session 2'. |
10 void main() { | 10 void main() { |
11 // Create MQTT client. | 11 // Create MQTT client. |
12 Client c = new Client('tcp://test.mosquitto.org:1883', 'test123-client1', | 12 Client c = new Client('tcp://test.mosquitto.org:1883', 'test123-client1', |
13 protocolVersion: 3); | 13 protocolVersion: 3); |
14 | 14 |
15 // Publish some messages. | 15 // Publish some messages. |
16 for (int i = 1; i <= 3; i++) { | 16 for (int i = 1; i <= 3; i++) { |
17 c.publish('Message $i', '/foo/bar'); | 17 c.publish('Message $i', '/foo/bar'); |
18 c.publish('Message $i', '/foo/baz'); | 18 c.publish('Message $i', '/foo/baz'); |
19 } | 19 } |
20 | 20 |
21 // Clean up. | 21 // Clean up. |
22 c.disconnect(); | 22 c.disconnect(); |
23 } | 23 } |
OLD | NEW |