// Weather proxy device

#include "zhelpers.h"

int main (void)
void *context = zmq_init (1);

// This is where the weather server sits
void *frontend = zmq_socket (context, ZMQ_SUB);
zmq_connect (frontend, "tcp://");

// This is our public endpoint for subscribers
void *backend = zmq_socket (context, ZMQ_PUB);
zmq_bind (backend, "tcp://");

// Subscribe on everything
zmq_setsockopt (frontend, ZMQ_SUBSCRIBE, "", 0);

// Shunt messages out to our own subscribers
while (1) {
while (1) {
zmq_msg_t message;
int64_t more;

// Process all parts of the message
zmq_msg_init (&message);
zmq_recv (frontend, &message, 0);
size_t more_size = sizeof (more);
zmq_getsockopt (frontend, ZMQ_RCVMORE, &more, &more_size);
zmq_send (backend, &message, more? ZMQ_SNDMORE: 0);
zmq_msg_close (&message);
if (!more)
break; // Last message part
// We don't actually get here but if we did, we'd shut down neatly
zmq_close (frontend);
zmq_close (backend);
zmq_term (context);
return 0;