ZeroMQ的EPGM无法在天气PUB-SUB演示中运行 [英] ZeroMQ's EPGM not working in weather PUB-SUB demo
问题描述
我用openpgm编译了libzmq,在Windows下没有任何更改.此处的代码摘自 ZeroMQ指南(天气发布者"服务器/客户).但是,如果我将"tcp"更改为"epgm",它将不再起作用(未收到数据,但已建立连接).
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);
}
我在不同的线程中运行两个函数,使用tcp,一切正常.
I run two functions in different threads, with tcp anything works as expected.
我尝试使用cmd.exe进行路由打印0.0.0.0",并使用接口IP(192.168.137.64)作为前缀,而不是如RFC中所示的"eth0":epgm://192.168.137.64; 127.0.0.1 :5556进行连接和/或绑定,但这会破坏我的套接字并引发错误.
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.
"PGM"还需要管理员权限,我现在无法对其进行测试.
Also "PGM" requires administrator rights and i cannot test it now.
错误不不支持协议" .errno设置为B(11),我不明白这是什么意思(没有相关文档).
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).
推荐答案
EPGM有点挑剔. 根据此列表帖子,如果您使用EPGM,您的发布者和订阅者 必须位于单独的主机上. 这里有更多详细信息,看来这是ZMQ团队的故意选择.
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.
因此,可以通过在单独的计算机上旋转PUB和SUB进行尝试(当然,相应地更改网络地址).
So, try it by spinning up your PUB and SUB on separate machines (changing the network addresses accordingly, of course).
这篇关于ZeroMQ的EPGM无法在天气PUB-SUB演示中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!