summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-07-14 18:49:03 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2023-07-14 18:49:03 +0200
commit2e02fd6b93606656d04e31e4c351d9658dd41f0a (patch)
treeee341a2101fb538cf2084d91046cbf41b5fa0c7f /src
parentd89f9840a5f97be75a2a4cecbd64fb6c4bd7e9f3 (diff)
Minor changes
Diffstat (limited to 'src')
-rw-r--r--src/client/main.c35
-rw-r--r--src/publisher/main.c26
2 files changed, 54 insertions, 7 deletions
diff --git a/src/client/main.c b/src/client/main.c
index 6ff8ae1..5204ae3 100644
--- a/src/client/main.c
+++ b/src/client/main.c
@@ -1,7 +1,36 @@
+// Weather update client
+// Connects SUB socket to tcp://localhost:5556
+// Collects weather updates and finds avg temp in zipcode
+#include <zmq.h>
+#include <assert.h>
+#include <time.h>
+#include <string.h>
+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");
+ assert (rc == 0);
+ // Subscribe to zipcode, default is NYC, 10001
+ // Subscribe to zipcode, default is NYC, 10001
+ const char *filter = "Hello";
+ rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE,
+ filter, strlen(filter));
+ assert (rc == 0);
-int main(){
+ // Process 100 updates
+ int update_nbr;
+ char buffer[10];
+ for (update_nbr = 0; update_nbr < 100; update_nbr++) {
+ zmq_recv (subscriber, buffer, 10, 0);
+ printf("Received!");
+ }
- return 0;
-}
+ zmq_close (subscriber);
+ zmq_ctx_destroy (context);
+ return 0;
+} \ No newline at end of file
diff --git a/src/publisher/main.c b/src/publisher/main.c
index 6ff8ae1..0abfefb 100644
--- a/src/publisher/main.c
+++ b/src/publisher/main.c
@@ -1,7 +1,25 @@
+// Weather update server
+// Binds PUB socket to tcp://*:5556
+// Publishes random weather updates
+#include <zmq.h>
+#include <assert.h>
+#include <time.h>
+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");
+ assert (rc == 0);
-int main(){
-
- return 0;
-}
+ // Initialize random number generator
+ while (1) {
+ zmq_send (publisher, "Hello World", 5, 0);
+ printf("AA\n");
+ }
+ zmq_close (publisher);
+ zmq_ctx_destroy (context);
+ return 0;
+} \ No newline at end of file