Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Run Client of PAIR Pattern.
- *
- * $ clang++ pair_client.cpp -lzmq -o pair_client.exe
- */
- #include <zmq.hpp>
- #include <chrono>
- #include <iostream>
- #include <cstdlib>
- #include <unistd.h>
- #include <sys/wait.h>
- int s_send(void *socket, char *string)
- {
- int size = zmq_send(socket, string, strlen(string), 0);
- return size;
- }
- int s_recv(void *socket, char buffer[])
- {
- int size = zmq_recv(socket, buffer, 255, 0);
- return size;
- }
- int run(void)
- {
- std::cout << "Starting PAIR Client.\n";
- void* context = zmq_ctx_new();
- void* subscriber = zmq_socket(context, ZMQ_PAIR);
- {
- auto const rc = zmq_connect(subscriber, "tcp://localhost:5556");
- assert(rc == 0);
- }
- char buffer[255] = {'\0'};
- int const count = 10;
- for (int i = 0; i < count; ++i) {
- s_recv(subscriber, buffer);
- buffer[10] = '\0';
- std::cout << "Received message=\"" << buffer << "\"\n";
- }
- zmq_close(subscriber);
- zmq_ctx_destroy(context);
- std::cout << "Finished.\n";
- return 0;
- }
- int main(void)
- {
- run();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement