ina260-zmq-publisher/src/publisher.c

58 lines
1.4 KiB
C
Raw Normal View History

2023-07-14 18:49:03 +02:00
// Weather update server
// Binds PUB socket to tcp://*:5556
// Publishes random weather updates
2023-07-14 18:26:31 +02:00
2023-07-14 18:49:03 +02:00
#include <zmq.h>
#include <assert.h>
#include <time.h>
2023-07-15 12:14:22 +02:00
#include <dirent.h>
2023-07-14 18:26:31 +02:00
2023-07-15 08:38:33 +02:00
#include "utils.h"
2023-07-14 19:29:18 +02:00
2023-07-15 12:14:22 +02:00
// Global:
char *__logdir;
int __loginterval;
2023-07-15 11:49:17 +02:00
int main (int argc, char *argv [])
2023-07-14 18:49:03 +02:00
{
2023-07-15 12:14:22 +02:00
if(argc != 3){
printf("Usage: %s <abslogdir> <loginterval>",argv[0]);
exit(1);
}
//----- Init global variables
__logdir=argv[1];
__loginterval=atoi(argv[2]);
DIR *dr = opendir(__logdir);
struct dirent *de; // Pointer for directory entry
for(int i=0;i<0;i++){
int interval=INTERVAL(__loginterval);
int interval_next=INTERVAL_NEXT(__loginterval);
while ((de = readdir(dr)) != NULL){
if(strcmp(de->d_name,".") && strcmp(de->d_name,"..")){
char *client=de->d_name;
printf("aa%s\n",client);
}
}
}
closedir(dr);
return 0;
2023-07-14 18:49:03 +02:00
// Prepare our context and publisher
void *context = zmq_ctx_new ();
void *publisher = zmq_socket (context, ZMQ_PUB);
2023-07-14 19:29:18 +02:00
int rc = zmq_bind (publisher, "tcp://*:"STRINGIFY(PUBLISHER_PORT));
2023-07-14 18:49:03 +02:00
assert (rc == 0);
2023-07-14 18:26:31 +02:00
2023-07-14 18:49:03 +02:00
// 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;
}