04-retain-qos0.cpp 769 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <cstring>
  2. #include <mosquittopp.h>
  3. static int run = -1;
  4. class mosquittopp_test : public mosqpp::mosquittopp
  5. {
  6. public:
  7. mosquittopp_test(const char *id);
  8. void on_connect(int rc);
  9. };
  10. mosquittopp_test::mosquittopp_test(const char *id) : mosqpp::mosquittopp(id)
  11. {
  12. }
  13. void mosquittopp_test::on_connect(int rc)
  14. {
  15. if(rc){
  16. exit(1);
  17. }else{
  18. publish(NULL, "retain/qos0/test", strlen("retained message"), "retained message", 0, true);
  19. }
  20. }
  21. int main(int argc, char *argv[])
  22. {
  23. struct mosquittopp_test *mosq;
  24. int port = atoi(argv[1]);
  25. mosqpp::lib_init();
  26. mosq = new mosquittopp_test("retain-qos0-test");
  27. mosq->connect("localhost", port, 60);
  28. while(run == -1){
  29. mosq->loop();
  30. }
  31. delete mosq;
  32. delete mosq;
  33. mosqpp::lib_cleanup();
  34. return run;
  35. }