PracticeDev/study_clang/zmq/reqrep/server.c

34 lines
904 B
C

#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
int main (void)
{
// Socket to talk to clients
void *context = zmq_ctx_new ();
void *responder = zmq_socket (context, ZMQ_REP);
unsigned int uiTimeout = 5 * 1000;
// zmq_setsockopt(responder, ZMQ_RCVTIMEO, &uiTimeout, sizeof(uiTimeout));
zmq_setsockopt(responder, ZMQ_SNDTIMEO, &uiTimeout, sizeof(uiTimeout));
int rc = zmq_bind (responder, "tcp://*:5555");
assert (rc == 0);
while (1) {
char buffer [10];
int recv_num = zmq_recv (responder, buffer, sizeof buffer, 0);
if(recv_num < 0)
{
printf("1111111111111111111\n");
continue;
}
printf ("Received %s\n", buffer);
sleep (4); // Do some 'work'
zmq_send (responder, "World", 5, 0);
// sleep(4);
}
return 0;
}