Working through the weather update pub/sub example
This commit is contained in:
parent
c3731f19a7
commit
b79dfcbc61
1
zeromq/.gitignore
vendored
1
zeromq/.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
hwserver
|
hwserver
|
||||||
hwclient
|
hwclient
|
||||||
|
wuserver
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
CFLAGS += -I. -I/usr/local/include
|
CFLAGS += -I. -I/usr/local/include
|
||||||
LDFLAGS += -lstdc++ -lpthread -luuid -lrt
|
LDFLAGS += -lstdc++ -lpthread -luuid -lrt
|
||||||
|
LIBZMQ := /usr/local/lib/libzmq.a
|
||||||
|
|
||||||
|
|
||||||
all: hwserver hwclient
|
%:%.c
|
||||||
|
$(CC) $(CFLAGS) -o $@ $^ $(LIBZMQ) $(LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
hwserver: hwserver.c /usr/local/lib/libzmq.a
|
all: hwserver hwclient wuserver
|
||||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
|
||||||
|
|
||||||
|
|
||||||
hwclient: hwclient.c /usr/local/lib/libzmq.a
|
|
||||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
24
zeromq/wuserver.c
Normal file
24
zeromq/wuserver.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include "zhelpers.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
void *context = zmq_init(1);
|
||||||
|
void *publisher = zmq_socket(context, ZMQ_PUB);
|
||||||
|
zmq_bind(publisher, "tcp://*:5556");
|
||||||
|
zmq_bind(publisher, "ipc://weather.ipc");
|
||||||
|
|
||||||
|
srandom((unsigned) time (NULL));
|
||||||
|
while (1) {
|
||||||
|
int zipcode, temperature, relhumidity;
|
||||||
|
zipcode = randof(100000);
|
||||||
|
temperature = randof(215) - 80;
|
||||||
|
relhumidity = randof(50) + 10;
|
||||||
|
|
||||||
|
char update[20];
|
||||||
|
sprintf(update, "%05d %d %d", zipcode, temperature, relhumidity);
|
||||||
|
s_send(publisher, update);
|
||||||
|
}
|
||||||
|
zmq_close(publisher);
|
||||||
|
zmq_term(context);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user