Minor changes

This commit is contained in:
Loic Guegan 2023-07-14 18:49:03 +02:00
parent d89f9840a5
commit 2e02fd6b93
6 changed files with 55 additions and 98 deletions
src
client
publisher

View file

@ -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;
}

View file

@ -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;
}