Filling in the weather update client

cat-town
Dan Buch 13 years ago
parent b79dfcbc61
commit afe51e924f

1
zeromq/.gitignore vendored

@ -1,3 +1,4 @@
hwserver
hwclient
wuserver
wuclient

@ -7,7 +7,7 @@ LIBZMQ := /usr/local/lib/libzmq.a
$(CC) $(CFLAGS) -o $@ $^ $(LIBZMQ) $(LDFLAGS)
all: hwserver hwclient wuserver
all: hwserver hwclient wuserver wuclient
.PHONY: all

@ -0,0 +1,30 @@
#include "zhelpers.h"
int main(int argc, char *argv[])
{
void *context = zmq_init(1);
printf("Collecting updates from weather server...\n");
void *subscriber = zmq_socket(context, ZMQ_SUB);
zmq_connect(subscriber, "tcp://localhost:5556");
// Subscribe to zipcode, default is NYC, 10001
char *filter = (argc > 1) ? argv[1]: "10001";
zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, filter, strlen(filter));
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_term(context);
return 0;
}
Loading…
Cancel
Save