Filling in the example C client, too
This commit is contained in:
parent
7f8c9c9052
commit
a600b87d42
1
zeromq/.gitignore
vendored
1
zeromq/.gitignore
vendored
@ -1 +1,2 @@
|
||||
hwserver
|
||||
hwclient
|
||||
|
@ -2,5 +2,15 @@ CFLAGS += -I. -I/usr/local/include
|
||||
LDFLAGS += -lstdc++ -lpthread -luuid -lrt
|
||||
|
||||
|
||||
all: hwserver hwclient
|
||||
|
||||
|
||||
hwserver: hwserver.c /usr/local/lib/libzmq.a
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
|
||||
hwclient: hwclient.c /usr/local/lib/libzmq.a
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
|
||||
.PHONY: all
|
||||
|
32
zeromq/hwclient.c
Normal file
32
zeromq/hwclient.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <zmq.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
void *context = zmq_init(1);
|
||||
|
||||
printf("Connecting to hello world server.\n");
|
||||
void *requester = zmq_socket(context, ZMQ_REQ);
|
||||
zmq_connect(requester, "tcp://localhost:5555");
|
||||
|
||||
int request_nbr;
|
||||
for (request_nbr = 0; request_nbr != 10; request_nbr++) {
|
||||
zmq_msg_t request;
|
||||
zmq_msg_init_size(&request, 5);
|
||||
memcpy(zmq_msg_data(&request), "Hello", 5);
|
||||
printf("Sending Hello %d...\n", request_nbr);
|
||||
zmq_send(requester, &request, 0);
|
||||
zmq_msg_close(&request);
|
||||
|
||||
zmq_msg_t reply;
|
||||
zmq_msg_init(&reply);
|
||||
zmq_recv(requester, &reply, 0);
|
||||
printf("Received World %d\n", request_nbr);
|
||||
zmq_msg_close(&reply);
|
||||
}
|
||||
zmq_close(requester);
|
||||
zmq_term(context);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user