box-o-sand/zeromq/hwserver.c
Dan Buch ccac55c639 Poking at zeromq stuff again
found some tabs!  eeeek!
2012-05-07 07:45:02 -04:00

39 lines
850 B
C

#include <zmq.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#define BIND_ADDR "tcp://*:5555"
int main(void)
{
void *context = zmq_init(1);
void *responder = zmq_socket(context, ZMQ_REP);
printf("Binding server to %s\n", BIND_ADDR);
printf("pid=%d\n", getpid());
zmq_bind(responder, BIND_ADDR);
printf("Starting loop.\n");
while(1) {
zmq_msg_t request;
zmq_msg_init(&request);
zmq_recv(responder, &request, 0);
printf("Received Hello\n");
zmq_msg_close(&request);
sleep(1);
zmq_msg_t reply;
zmq_msg_init_size(&reply, 5);
memcpy(zmq_msg_data(&reply), "World", 5);
zmq_send(responder, &reply, 0);
zmq_msg_close(&reply);
}
zmq_close(responder);
zmq_term(context);
return 0;
}