Skip to content

Instantly share code, notes, and snippets.

@norganna norganna/gist:7461882
Last active Dec 28, 2015

Embed
What would you like to do?
// Weather update client
// Connects SUB socket to tcp://localhost:5556
#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://localhost:5556");
assert (rc == 0);
// Subscribe to zipcode, default is NYC, 10001
char *filter = "10001 ";
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, filter, strlen (filter));
assert (rc == 0);
filter = "10002 ";
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, filter, strlen (filter));
assert (rc == 0);
while (1) {
char *string = s_recv (subscriber);
printf("Got: %s\n", string);
free (string);
}
zmq_close (subscriber);
zmq_ctx_destroy (context);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.