2012-03-16 01:43:01 +00:00
|
|
|
#include <zmq.h>
|
|
|
|
#include <stdio.h>
|
2012-05-07 11:45:02 +00:00
|
|
|
#include <sys/types.h>
|
2012-03-16 01:43:01 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-05-07 11:45:02 +00:00
|
|
|
#define BIND_ADDR "tcp://*:5555"
|
|
|
|
|
2012-03-16 01:43:01 +00:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
void *context = zmq_init(1);
|
|
|
|
|
|
|
|
void *responder = zmq_socket(context, ZMQ_REP);
|
2012-05-07 11:45:02 +00:00
|
|
|
printf("Binding server to %s\n", BIND_ADDR);
|
|
|
|
printf("pid=%d\n", getpid());
|
|
|
|
zmq_bind(responder, BIND_ADDR);
|
2012-03-16 01:43:01 +00:00
|
|
|
|
2012-05-07 11:45:02 +00:00
|
|
|
printf("Starting loop.\n");
|
2012-03-16 01:43:01 +00:00
|
|
|
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;
|
|
|
|
}
|