Search code examples
czeromqpgm-protocol

Don't get messages with epgm://, while with tcp:// do. Why?


I try to use the weather example from the ZeroMQ guide, with an epgm:// transport-class. At first my code:

// Publisher

#include "zhelpers.h"

int main (void) {
    //  Prepare our context and publisher
    void *context = zmq_ctx_new ();
    void *publisher = zmq_socket ( context, ZMQ_PUB );
    // int rc = zmq_bind ( publisher, "tcp://*:5556" );
       int rc = zmq_bind ( publisher, "epgm://192.168.1.4;224.0.0.251:5556" );
    assert ( rc == 0 );

    //  Initialize random number generator
    srandom ( (unsigned) time (NULL) );
    while (1) {
        //  Get values that will fool the boss
        int zipcode, temperature, relhumidity;
        zipcode     = randof (100000);
        temperature = randof (215) - 80;
        relhumidity = randof (50) + 10;

        //  Send a message to all subscribers
        char update [20];
        sprintf ( update, "%05d %d %d", zipcode, temperature, relhumidity );
        s_send ( publisher, update );
    }
    zmq_close ( publisher );
    zmq_ctx_destroy ( context );
    return 0;
}

    // Subscriber
    #include "zhelpers.h"

    int main ( int argc, char *argv [] )
    {
        //  Socket to talk to server
        printf ( "Collecting updates from weather server…\n" );
        void *context = zmq_ctx_new ();
        void *subscriber = zmq_socket ( context, ZMQ_SUB );
        // int rc = zmq_connect ( subscriber, "tcp://192.168.1.4:5556" );
           int rc = zmq_connect ( subscriber, "epgm://192.168.1.9;224.0.0.251:5556" );
        assert ( rc == 0 );

        //  Subscribe to zipcode, default is NYC, 10001
        char *filter = ( argc > 1 )? argv [1]: "10001 ";
        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 < 100; update_nbr++ ) {
            char *string = s_recv ( subscriber );

            int zipcode, temperature, relhumidity;
            sscanf ( string, "%d %d %d",
                    &zipcode, &temperature, &relhumidity );
            total_temp += temperature;
            free ( string );
        }
        printf ( "Average temperature for zipcode '%s' was %dF\n",
            filter, (int) ( total_temp / update_nbr ) );

        zmq_close ( subscriber );
        zmq_ctx_destroy ( context );
        return 0;
    }
  1. I've tried this code with tcp:// on the same hosts ( see comments ) and it works fine.
  2. I tried the multicast address with this example Openbook Linux ( with my multicast address ), and I got the messages.
  3. I installed ZeroMQ with pgm:// ( before I was getting assertion faults ).
  4. My hosts both are Ubuntu 16.04 systems
  5. I'm using ZeroMQ 4

My problem is that I don't get any messages with epgm://. Both programs were running, but no message were received. What am I missing? I don't understand what could be wrong.


Solution

  • For later visitors of the question, the code is fine and running. To see if it works on your system, change the for-loop to one loop and set the zipcode in the publisher on 10001, if you start the subscriber without an argument.