ina260-zmq-publisher/src/client.c

47 lines
962 B
C
Raw Normal View History

2023-07-14 18:49:03 +02:00
// 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>
2023-07-14 18:28:02 +02:00
2023-07-15 08:38:33 +02:00
#include "utils.h"
2023-07-14 19:29:18 +02:00
2023-07-14 18:49:03 +02:00
int main (int argc, char *argv [])
{
2023-07-15 14:02:43 +02:00
if(argc != 3){
printf("Usage: %s <address> <port>",argv[0]);
exit(1);
}
char *ip=argv[1];
int port=atoi(argv[2]);
// Socket to talk to server
void *context = zmq_ctx_new ();
void *subscriber = zmq_socket (context, ZMQ_SUB);
char bindto[30];
sprintf(bindto,"tcp://%s:%d",ip,port);
int rc = zmq_connect (subscriber, bindto);
if(rc!=0){
printf("Failed to bind zmq on %s\n",bindto);
exit(1);
}
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE,
ZMQ_TOKEN, strlen(ZMQ_TOKEN));
char buffer[10];
zmq_recv (subscriber, buffer, 10, 0);
printf("Received!");
zmq_close (subscriber);
zmq_ctx_destroy (context);
return 0;
2023-07-14 18:49:03 +02:00
}