简体   繁体   中英

Why a ZeroMQ PGM multicast is not receiving a Multicast message? ( C++, Windows )

Environment setup:
- Both a multicast send & receive applications are running in the same machine

I am integrating ZeroMQ multicast with OpenPGM support, but facing problem in below my sample code.

ie "Multicast message is not received" in receiver application. Kindly correct me if I am doing wrong. Also not able to find proper examples on ZeroMQ PGM multicast requirement.

// ZMQ_pgm_receive.cpp : 
//
//Headers
#include "stdafx.h"
#include "zmq.h"
#include <iostream>
#include <windows.h>

std::string fullurl = "pgm://eth0;239.255.0.1:30001";
static int roundtrip_count = 50;
static size_t message_size = 4;

int _tmain(int argc, _TCHAR* argv[])
{
    void *ctx = NULL,
         *s = NULL;
    int con;
    int i;

    ctx = zmq_init (1);
    if (!ctx) {
        printf ("error in zmq_init: %s\n", zmq_strerror (errno));
        return -1;
    }

    s = zmq_socket (ctx, ZMQ_SUB);
    if (!s) {
        printf ("error in zmq_socket: %s\n", zmq_strerror (errno));
        return -1;
    }


    con = zmq_bind(socket, fullurl.c_str()); 
    if (con == 0) {
        printf ("error in zmq_bind: %s\n", zmq_strerror (errno));
        return -1;
    }
    zmq_msg_t msg;

    int rc = zmq_msg_init (&msg);
    if (rc != 0) {
        printf ("error in zmq_msg_init: %s\n", zmq_strerror (errno));
        return -1;
    }

    for (i = 0; i != roundtrip_count; i++) {

        rc = zmq_recvmsg (s, &msg, 0);
        if (rc < 0) {
            printf ("error in zmq_recvmsg: %s\n", zmq_strerror (errno));
            return -1;
        }
        printf("message received\n");

        if (zmq_msg_size (&msg) != message_size) {
            printf ("message of incorrect size received\n");
            return -1;
        }
        Sleep(1000);

    }

    rc = zmq_msg_close (&msg);
    if (rc != 0) {
        printf ("error in zmq_msg_close: %s\n", zmq_strerror (errno));
        return -1;
    }

    rc = zmq_close (s);
    if (rc != 0) {
        printf ("error in zmq_close: %s\n", zmq_strerror (errno));
        return -1;
    }
    /*rc = zmq_ctx_term (ctx);
    if (rc != 0) {
        printf ("error in zmq_ctx_term: %s\n", zmq_strerror (errno));
        return -1;
    }
ctx = NULL;
*/

return 0;
}

// ZMQ_pgm_send.cpp :
//
#include "stdafx.h"
#include "zmq.h"
#include <iostream>
#include <windows.h>

std::string fullurl = "pgm://eth0;239.255.0.1:30001";    
static int roundtrip_count = 50;
static size_t message_size = 4;

int _tmain(int argc, _TCHAR* argv[])
{
    void *ctx = NULL,
         *s = NULL;
    int con;
    int i;

    ctx = zmq_init (1);
    if (!ctx) {
        printf ("error in zmq_init: %s\n", zmq_strerror (errno));
        return -1;
    }

    s = zmq_socket (ctx, ZMQ_PUB);
    if (!s) {
        printf ("error in zmq_socket: %s\n", zmq_strerror (errno));
        return -1;
    }

    con = zmq_connect(socket, fullurl.c_str()); 
    if (con == 0) {
        printf ("error in zmq_connect: %s\n", zmq_strerror (errno));
        return -1;
    }
    zmq_msg_t msg;

    int rc = zmq_msg_init_size (&msg,message_size);
    if (rc != 0) {
        printf ("error in zmq_msg_init: %s\n", zmq_strerror (errno));
        return -1;
    }

    memset(zmq_msg_data (&msg),'A', message_size ); 
    for (i = 0; i != roundtrip_count; i++) {

        rc = zmq_sendmsg (s, &msg, 0);
        if (rc < 0) {
            printf ("error in zmq_sendmsg: %s\n", zmq_strerror (errno));
            return -1;
        }
    }

    rc = zmq_msg_close (&msg);
    if (rc != 0) {
        printf ("error in zmq_msg_close: %s\n", zmq_strerror (errno));
        return -1;
    }

    rc = zmq_close (s);
    if (rc != 0) {
        printf ("error in zmq_close: %s\n", zmq_strerror (errno));
        return -1;
    }
    /*rc = zmq_ctx_term (ctx);
    if (rc != 0) {
        printf ("error in zmq_ctx_term: %s\n", zmq_strerror (errno));
        return -1;
    }
    ctx = NULL;
    */

    return 0;
}

Please correct me if I am doing wrong.

Having solved the [Step 0] , proposed above in the comment,
one ought
detect

a Missing ZMQ_SUBSCRIBE setup, thus SUB-side filters all traffic

ZMQ_SUBSCRIBE : Establish message filter


The ZMQ_SUBSCRIBE option shall establish a new message filter on a ZMQ_SUB socket. Newly created ZMQ_SUB sockets shall filter out all incoming messages, therefore you should call this option to establish an initial message filter.

An empty option_value of length zero shall subscribe to all incoming messages. A non-empty option_value shall subscribe to all messages beginning with the specified prefix. Multiple filters may be attached to a single ZMQ_SUB socket, in which case a message shall be accepted if it matches at least one filter.


Anyway, welcome & enjoy these smart tools for distributed systems computing!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM