cwzx/nngpp

nngpp sub socket can't recv any msg

Closed this issue · 1 comments

there is no pub/sub demo in nggpp project?

I'm new nngpp and I try to use pub/sub socket to write a demo,but it's not work.
the sub socket can't recv any msg.

my code as below:
server :

int main() try {
    LOGD(TAG, "start");

    nng::socket pub_socket = nng::pub::open();
    pub_socket.listen("ipc://@pubsub.ipc");
    while(1) {
        LOGD(TAG, "pub data ");
        pub_socket.send("BATTERY");
        nng::msleep(1000);
    }

    LOGD(TAG, "end");

} catch(const nng::exception& e) {
 return 1;
}

client:

int main() try {
    LOGD(TAG, "start");

    nng::socket sub_socket = nng::sub::open();
    sub_socket.set_opt_string(NNG_OPT_SUB_SUBSCRIBE, "");
    sub_socket.dial("ipc://@pubsub.ipc");
    while(1) {
        LOGD(TAG, "recv message start...");
        nng::buffer msg = sub_socket.recv(NNG_FLAG_ALLOC);
        LOGD(TAG, "recv message %s", msg.data());
        nng::msleep(1000);
    }

    LOGD(TAG, "end");

} catch(const nng::exception& e) {
    return 1;
}

cwzx commented

See #9