CZMQ : Unable to receive message

给你一囗甜甜゛ 提交于 2019-12-06 07:29:12

By default there is no subscription on a SUB socket. Try using the variant that takes a subscription :

zsock_t* zsock_new_sub (const char *endpoints, const char *subscribe)

Or create the subscription after :

zsock_set_subscribe (void *zsock, const char *subscribe);

The empty string subscribes to everything.

There two problems in the above program.

  1. The absence of 'zsock_set_subscribe' as @david points out in an earlier comment.
  2. The publisher sends the message before subscriber has an opportunity to connect, hence the message would be lost and the subscriber would continue to wait for a message which would never come.

Solution :

  1. Adding the 'zsock_set_subscribe' after the subscriber socket is initialized.
  2. Initializing the subscriber before the publisher and adding a small delay (say 1 sec) immediately after the publisher' so as to provide enough time for the subscriber to connect and eventually receive the message.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!