01-no-clean-session.c 517 B

12345678910111213141516171819202122232425262728293031
  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-no-clean-session", false, NULL);
  14. if(mosq == NULL){
  15. return 1;
  16. }
  17. rc = mosquitto_connect(mosq, "localhost", port, 60);
  18. while(run == -1){
  19. mosquitto_loop(mosq, -1, 1);
  20. }
  21. mosquitto_destroy(mosq);
  22. mosquitto_lib_cleanup();
  23. return run;
  24. }