01-will-unpwd-set.cpp 706 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. };
  9. mosquittopp_test::mosquittopp_test(const char *id) : mosqpp::mosquittopp(id)
  10. {
  11. }
  12. int main(int argc, char *argv[])
  13. {
  14. struct mosquittopp_test *mosq;
  15. int port = atoi(argv[1]);
  16. mosqpp::lib_init();
  17. mosq = new mosquittopp_test("01-will-unpwd-set");
  18. mosq->username_pw_set("oibvvwqw", "#'^2hg9a&nm38*us");
  19. mosq->will_set("will-topic", strlen("will message"), "will message", 2, false);
  20. mosq->connect("localhost", port, 60);
  21. while(run == -1){
  22. mosq->loop();
  23. }
  24. delete mosq;
  25. delete mosq;
  26. mosqpp::lib_cleanup();
  27. return run;
  28. }