【问题标题】:ZeroMQ's EPGM not working in weather PUB-SUB demoZeroMQ 的 EPGM 在天气 PUB-SUB 演示中不起作用
【发布时间】:2016-03-20 19:27:47
【问题描述】:

我已经用 openpgm 编译了 libzmq,在 windows 下没有任何变化。这里的代码取自ZeroMQ Guide(“天气发布者”服务器/客户端)。但是,如果我将“tcp”更改为“epgm”,它就不再起作用(没有收到数据,但建立了连接)。

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 一切都按预期工作。

我尝试使用 cmd.exe 执行“路由打印 0.0.0.0”并使用接口 IP (192.168.137.64) 作为前缀而不是 RFC 中所示的“eth0”:epgm://192.168.137.64;127.0.0.1连接和/或绑定时:5556,但这会破坏我的套接字并引发错误。

另外,“PGM”需要管理员权限,我现在无法测试。

错误不是“不支持协议” errno 设置为 B (11),我不明白这是什么意思(没有文档)。

【问题讨论】:

    标签: windows network-programming zeromq pgm-protocol


    【解决方案1】:

    EPGM 有点挑剔。 According to this list post,如果您使用 EPGM,您的发布者和订阅者必须位于不同的主机上。 More details here,看来这是ZMQ团队的一个深思熟虑的选择。

    因此,请尝试在不同的机器上启动 PUB 和 SUB(当然要相应地更改网络地址)。

    【讨论】:

      【解决方案2】:

      原因可能是windows不支持loopback capture接口。我尝试了在 linux 上将协议更改为 epgm 的天气示例,它工作正常(嗯,显示了一些有关环回的警告,但消息传输正确)

      【讨论】:

      • 我不确定您所说的 loopback capture interface support 是什么意思。你能澄清一下吗?
      猜你喜欢
      • 2011-09-08
      • 2016-01-28
      • 2012-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-24
      • 2015-04-21
      • 2013-06-20
      相关资源
      最近更新 更多