From 6172ad70924be37de833facb41365eff1cec497b Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Fri, 14 Jul 2023 19:29:18 +0200 Subject: [PATCH] Minor changes --- Makefile | 4 ++++ client | Bin 15992 -> 15992 bytes publisher | Bin 15688 -> 15688 bytes src/client/Makefile | 2 +- src/client/main.c | 9 ++++++++- src/publisher/Makefile | 2 +- src/publisher/main.c | 9 ++++++++- 7 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index e889f55..9606e51 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,17 @@ +PUBLISHER_PORT=5556 CC="gcc" +CFLAGS= all: publisher client publisher: echo "Building publisher..." + CFLAGS+=-DPUBLISHER_PORT=$(PUBLISHER_PORT) \ $(MAKE) -C src/publisher/ CC=$(CC) OUT=$(PWD) client: echo "Building client..." + CFLAGS+=-DPUBLISHER_PORT=$(PUBLISHER_PORT) \ $(MAKE) -C src/client/ CC=$(CC) OUT=$(PWD) diff --git a/client b/client index 219fb854cb6f6023d94919e13116238e85f47e44..8da3fc3036dd9641bdde4825c05dfac555d924d5 100755 GIT binary patch delta 46 zcmV+}0MY;WeE58@hyxUt$t9sz0Df1clM#M<1dx8ZL8ObboCCrR0T+{B5?=uxv%eC# EEA18&EC2ui delta 46 zcmV+}0MY;WeE58@hyxURj)&LKPLp*D90IgW-JMIaK4T}doCCrR0T7d45?=uqv%eC# EEBUn(L;wH) diff --git a/publisher b/publisher index 44a2325e171c7b199f8f8bbc732a72df6bacf499..a4a8b88230003ca1826e678084adad9a77bf6cf0 100755 GIT binary patch delta 40 ycmV+@0N4M>ddPaPhyxU39c=sVJLhYw{z;(3m(%Jp*`fHeoC7@$0T#2`5pFBJt`u(o delta 40 wcmX?6b)srR2eU{-=$AP>vf;`RXL5@j6~iJYiA$zzp2KX*$H>3=mSCPX08jM}(*OVf diff --git a/src/client/Makefile b/src/client/Makefile index d370439..0ae633e 100644 --- a/src/client/Makefile +++ b/src/client/Makefile @@ -1,5 +1,5 @@ EXEC=client -CFLAGS=-lzmq +CFLAGS+=-lzmq all: main.c $(CC) $^ -o $(OUT)/$(EXEC) $(CFLAGS) diff --git a/src/client/main.c b/src/client/main.c index 5204ae3..e7ff4a5 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -6,13 +6,20 @@ #include #include +#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 diff --git a/src/publisher/Makefile b/src/publisher/Makefile index 605e667..57eccb9 100644 --- a/src/publisher/Makefile +++ b/src/publisher/Makefile @@ -1,5 +1,5 @@ EXEC=publisher -CFLAGS=-lzmq +CFLAGS+=-lzmq all: main.c $(CC) $^ -o $(OUT)/$(EXEC) $(CFLAGS) diff --git a/src/publisher/main.c b/src/publisher/main.c index 0abfefb..817d79f 100644 --- a/src/publisher/main.c +++ b/src/publisher/main.c @@ -6,12 +6,19 @@ #include #include +#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