[zeromq-dev] How to use the PGM

仇立偉 liwei_chour at mail.apex.com.tw
Tue Sep 3 08:36:52 CEST 2013


  I use the PUB-SUB pattern in my program. When I use the TCP protocol, It
works fine. But I change to the PGM protocol(using the same code), I can
send data, but can’t receive any data. Following are the Code


//Sender Code

    ctx = zmq_init (1);

    s = zmq_socket (ctx, ZMQ_PUB);

    rc = zmq_bind (s, "tcp://”);

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

        rc = zmq_msg_init_size (&msg, 50);

        unsigned char *msg_point = (unsigned char *)zmq_msg_data(&msg);

        memcpy(msg_point, (unsigned char *)&order, sizeof(unsigned int));

        rc = zmq_sendmsg (s, &msg, 0);

        rc = zmq_msg_close (&msg);



    rc = zmq_close (s);

    rc = zmq_term (ctx);


//Receive Code    

    ctx = zmq_init (1);

    s = zmq_socket (ctx, ZMQ_SUB);

    rc = zmq_connect (s, "tcp://”);

    rc = zmq_setsockopt (s, ZMQ_SUBSCRIBE, "", 0);

    rc = zmq_msg_init_size (&msg, message_size);

    while(1) {

        rc = zmq_recvmsg (s, &msg, 0);

        unsigned char *msg_point = (unsigned char *)zmq_msg_data(&msg);

        memcpy((unsigned char *)&order, msg_point, sizeof(unsigned int));

        print(“Get size=%d order=%d\n”, rc,order);


    rc = zmq_close (s);

    rc = zmq_term (ctx);


If I change “tcp://” to “pmg://;239.192.
1.1:8888”, it doesn’t work. Where do I make a mistake?

My platform is Windows 7 64bit and Using VS 2008. The PGM library download
from http://miru.hk/openpgm/



Liwei Chour in OFFICe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130903/a3a98461/attachment.htm>

More information about the zeromq-dev mailing list