Filling in the weather update client
This commit is contained in:
parent
b79dfcbc61
commit
afe51e924f
1
zeromq/.gitignore
vendored
1
zeromq/.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
hwserver
|
hwserver
|
||||||
hwclient
|
hwclient
|
||||||
wuserver
|
wuserver
|
||||||
|
wuclient
|
||||||
|
@ -7,7 +7,7 @@ LIBZMQ := /usr/local/lib/libzmq.a
|
|||||||
$(CC) $(CFLAGS) -o $@ $^ $(LIBZMQ) $(LDFLAGS)
|
$(CC) $(CFLAGS) -o $@ $^ $(LIBZMQ) $(LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
all: hwserver hwclient wuserver
|
all: hwserver hwclient wuserver wuclient
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
30
zeromq/wuclient.c
Normal file
30
zeromq/wuclient.c
Normal file
@ -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…
Reference in New Issue
Block a user