示例之libmosquitto_single_test

#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...

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章