01-will-unpwd-set.c 671 B

123456789101112131415161718192021222324252627282930313233
  1. #include <stdbool.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <mosquitto.h>
  6. static int run = -1;
  7. int main(int argc, char *argv[])
  8. {
  9. int rc;
  10. struct mosquitto *mosq;
  11. int port = atoi(argv[1]);
  12. mosquitto_lib_init();
  13. mosq = mosquitto_new("01-will-unpwd-set", true, NULL);
  14. if(mosq == NULL){
  15. return 1;
  16. }
  17. mosquitto_username_pw_set(mosq, "oibvvwqw", "#'^2hg9a&nm38*us");
  18. mosquitto_will_set(mosq, "will-topic", strlen("will message"), "will message", 2, false);
  19. rc = mosquitto_connect(mosq, "localhost", port, 60);
  20. while(run == -1){
  21. mosquitto_loop(mosq, -1, 1);
  22. }
  23. mosquitto_destroy(mosq);
  24. mosquitto_lib_cleanup();
  25. return run;
  26. }