Networking Reference
In-Depth Information
void* socket = zsocket_new(context, ZMQ_REP);
zsocket_bind(socket, "tcp://*:5050");
signal(SIGINT, exit);
printf("Starting server...\n");
zhash_t* map = zhash_new();
zhash_insert(map, "user_id", "1234");
zhash_insert(map, "user_email", "name@example.org");
for(;;) {
char* msg = zstr_recv(socket);
char* email = zhash_lookup(map, msg);
printf("Received: %s\n", msg);
if(email) {
zstr_send(socket, zhash_lookup(map, msg));
} else {
zstr_send(socket, "Not Found");
}
free(msg);
}
zsocket_destroy(context, socket);
zctx_destroy(&context);
return 0;
}
And the client code is as follows:
/*
Request - Reply
Using zhash.
 
Search MirCeyron ::




Custom Search