#ifndef LIBMOSQUITTO_TEST_SINGLE_HPP
#define LIBMOSQUITTO_TEST_SINGLE_HPP
#include<stdio.h>
#include<stdlib.h>
#include"mosquitto.h"
int test(){
int rc;
struct mosquitto_message *pMsg;
mosquitto_lib_init();
rc = mosquitto_subscribe_simple(
&pMsg,1,true,
"irc/#",0,
"test.mosquitto.org",1883,
NULL,60,true,
NULL,NULL,
NULL,NULL
);
if(rc){
printf("Error:%s\n",mosquitto_strerror(rc));
mosquitto_lib_cleanup();
return rc;
}
printf("%s %s\n",pMsg->topic,(char*)pMsg->payload);
mosquitto_lib_cleanup();
return rc;
}
#endif // LIBMOSQUITTO_TEST_SINGLE_HPP
運行結果:
Hello World!
irc/-lrluk-crew/usercount 1
Press <RETURN> to close this window...