Psenvsub

//
// Pubsub envelope subscriber
//

#include "zhelpers.h"

int main (void)
{
// Prepare our context and subscriber
void *context = zmq_init (1);
void *subscriber = zmq_socket (context, ZMQ_SUB);
zmq_connect (subscriber, "tcp://localhost:5563");
zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, "B", 1);

while (1) {
// Read envelope with address
char *address = s_recv (subscriber);
// Read message contents
char *contents = s_recv (subscriber);
printf ("[%s] %s\n", address, contents);
free (address);
free (contents);
}
// We never get here but clean up anyhow
zmq_close (subscriber);
zmq_term (context);
return 0;
}