PracticeDev/study_clang/zmq/zmq_experiment/weather_pub.c

35 lines
662 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include "zmq.h"
int main()
{
void* context = zmq_ctx_new();
assert(context != NULL);
void* publisher = zmq_socket(context, ZMQ_PUB);
assert(publisher != NULL);
int ret = zmq_bind(publisher, "tcp://*:5556");
assert(ret == 0);
int i = 0;
while(1)
{
char szBuf[1024] = {0};
snprintf(szBuf, sizeof(szBuf), "server i=%d", i);
ret = zmq_send(publisher, szBuf, strlen(szBuf) + 1, 0);
i++;
sleep(1);
}
zmq_close (publisher);
zmq_ctx_destroy (context);
return 0;
}