ZeroMQ's EPGM not working in weather PUB-SUB demo

匿名 (未验证) 提交于 2019-12-03 01:26:01

问题:

I have compiled libzmq with openpgm with no changes under windows. Code here is taken from ZeroMQ Guide ("weather publisher" server/client). But if i change "tcp" to "epgm" it doesn't work any more (data is not received, but connection is established).

void test_serv() {         //  Prepare our context and publisher     void *context = zmq_ctx_new();     void *publisher = zmq_socket(context, ZMQ_PUB);     int rc = zmq_bind(publisher, "epgm://127.0.0.1:5556");     assert(rc == 0);      //  Initialize random number generator     srandom((unsigned)time(NULL));     while (!stop_server)     {         //  Get values that will fool the boss         int zipcode, temperature, relhumidity;         zipcode = randof(1000) + 600;         temperature = randof(215) - 80;         relhumidity = randof(50) + 10;          //  Send message to all subscribers         char update[20];         sprintf(update, "%d %d %d", zipcode, temperature, relhumidity);         s_send(publisher, update);     }     LOG("END Server shutdown");     Sleep(500);     zmq_close(publisher);     zmq_ctx_destroy(context); }  void test_sock() {         //  Socket to talk to server     LOG("Collecting updates from weather server...");     void *context = zmq_ctx_new();     void *subscriber = zmq_socket(context, ZMQ_SUB);     int rc = zmq_connect(subscriber, "epgm://127.0.0.1:5556");     assert(rc == 0);      //  Subscribe to zipcode, default is NYC, 10001     char *filter = "1001 ";     rc = zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE,         filter, strlen(filter));     assert(rc == 0);      //  Process 100 updates     int update_nbr;     long total_temp = 0;     for (update_nbr = 0; update_nbr < 10; update_nbr++) {         char *string = s_recv(subscriber);          int zipcode, temperature, relhumidity;         sscanf(string, "%d %d %d",             &zipcode, &temperature, &relhumidity);         total_temp += temperature;         LOG(">> " << string);         free(string);     }     LOG("Average temperature for zipcode "<< filter << "was " << (int)(total_temp / update_nbr) << 'F');      zmq_close(subscriber);     zmq_ctx_destroy(context); } 

I run two functions in different threads, with tcp anything works as expected.

I have tried doing "route print 0.0.0.0" with cmd.exe and using interface IP (192.168.137.64) as prefix instead of "eth0" like shown in RFC: epgm://192.168.137.64;127.0.0.1:5556 on connect and/or bind, but this brokes my socket and raises error.

Also "PGM" requires administrator rights and i cannot test it now.

The error IS NOT "protocol not supported" errno is set to B (11) and i don't understand what does it mean (no docs on it).

回答1:

EPGM is a bit finicky. According to this list post, if you're using EPGM your publisher and subscriber must be on separate hosts. More details here, it looks like this was a deliberate choice by the ZMQ team.

So, try it by spinning up your PUB and SUB on separate machines (changing the network addresses accordingly, of course).



回答2:

The reason might be that windows does not support loopback capture interface. I tried weather example with protocol changed to epgm on linux and it works fine (well, shows some warnings about loopback, but the messages are transfered correctly)



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!