Networking Reference
In-Depth Information
// Let's initialize a socket to send the messages.
void* sender = zmq_socket(context, ZMQ_PUSH);
zmq_connect(sender, "tcp://localhost:5050");
for(;;) {
zmq_msg_t reply;
zmq_msg_init(&reply);
zmq_msg_recv(&reply, receiver, 0);
int length = zmq_msg_size(&reply);
char* msg = malloc(length + 1);
memcpy(msg, zmq_msg_data(&reply), length);
zmq_msg_close(&reply);
fflush(stdout);
double val = atof(msg);
printf("%.1f: %.1f\n", val, newton_sqrt(val));
sleep(1);
free(msg);
zmq_msg_t message;
char* ssend = "T";
int t_length = strlen(ssend);
zmq_msg_init_size(&message, t_length);
memcpy(zmq_msg_data(&message), ssend, t_length);
zmq_msg_send(&message, receiver, 0);
zmq_msg_close(&message);
}
zmq_close(receiver);
zmq_close(sender);
zmq_ctx_destroy(context);
return 0;
}
The following is the receiver code:
#include <stdlib.h>
#include <string.h>
#include "zmq.h"
 
Search MirCeyron ::




Custom Search