Skip to content

Commit 972ded9

Browse files
authored
The QoS=2 example didn't work
1 parent ba7c5e0 commit 972ded9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

README.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,25 @@ The underlying library is based on callbacks and asynchronous operation. As such
4646
```php
4747
<?php
4848

49-
$c = new Mosquitto\Client;
50-
$c->onConnect(function() use ($c) {
51-
$c->publish('mgdm/test', 'Hello', 0);
52-
$c->disconnect();
49+
use Mosquitto\Client;
50+
51+
$mid = 0;
52+
$c = new Mosquitto\Client("PHP");
53+
$c->onLog('var_dump');
54+
$c->onConnect(function() use ($c, &$mid) {
55+
$mid = $c->publish("mgdm/test", "Hello", 2);
56+
});
57+
58+
$c->onPublish(function($publishedId) use ($c, $mid) {
59+
if ($publishedId == $mid) {
60+
$c->disconnect();
61+
}
5362
});
5463

55-
$c->connect('test.mosquitto.org');
64+
$c->connect("localhost");
5665
$c->loopForever();
5766

58-
echo "Finished\n";
67+
echo "Finished"
5968
```
6069

6170
## Documentation

0 commit comments

Comments
 (0)