Minor changes

This commit is contained in:
Loic Guegan 2023-07-14 19:29:18 +02:00
parent 2e02fd6b93
commit 6172ad7092
7 changed files with 22 additions and 4 deletions

View file

@ -1,5 +1,5 @@
EXEC=client
CFLAGS=-lzmq
CFLAGS+=-lzmq
all: main.c
$(CC) $^ -o $(OUT)/$(EXEC) $(CFLAGS)

View file

@ -6,13 +6,20 @@
#include <time.h>
#include <string.h>
#define STR(symbol) #symbol
#define STRINGIFY(symbol) STR(symbol)
#ifndef PUBLISHER_PORT
#error PUBLISHER_PORT macro undefined
#endif
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");
int rc = zmq_connect (subscriber, "tcp://localhost:"STRINGIFY(PUBLISHER_PORT));
assert (rc == 0);
// Subscribe to zipcode, default is NYC, 10001

View file

@ -1,5 +1,5 @@
EXEC=publisher
CFLAGS=-lzmq
CFLAGS+=-lzmq
all: main.c
$(CC) $^ -o $(OUT)/$(EXEC) $(CFLAGS)

View file

@ -6,12 +6,19 @@
#include <assert.h>
#include <time.h>
#define STR(symbol) #symbol
#define STRINGIFY(symbol) STR(symbol)
#ifndef PUBLISHER_PORT
#error PUBLISHER_PORT macro undefined
#endif
int main (void)
{
// Prepare our context and publisher
void *context = zmq_ctx_new ();
void *publisher = zmq_socket (context, ZMQ_PUB);
int rc = zmq_bind (publisher, "tcp://*:5556");
int rc = zmq_bind (publisher, "tcp://*:"STRINGIFY(PUBLISHER_PORT));
assert (rc == 0);
// Initialize random number generator