PracticeDev/study_clang/zmq/zmq_experiment/weather_sub.c

39 lines
774 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include "zmq.h"
int main()
{
printf("Hello world!\n");
void* context = zmq_ctx_new();
assert(context != NULL);
void* subscriber = zmq_socket(context, ZMQ_SUB);
assert(subscriber != NULL);
int ret = zmq_connect(subscriber, "tcp://localhost:5556");
assert(ret == 0);
ret = zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "", 0);
assert(ret == 0);
while(1)
{
printf("into while\n");
char szBuf[1024] = {0};
ret = zmq_recv(subscriber, szBuf, sizeof(szBuf) - 1, 0);
if (ret > 0)
{
printf("%s\n", szBuf);
}
}
zmq_close(subscriber);
zmq_ctx_destroy(context);
return 0;
}