Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Run Server of PAIR Pattern.
- *
- * $ clang++ pair_server.cpp -lzmq -o pair_server.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 Server.\n";
- void* context = zmq_ctx_new();
- void* publisher = zmq_socket(context, ZMQ_PAIR);
- auto const rc = zmq_bind(publisher, "tcp://127.0.0.1:5556");
- assert(rc == 0);
- while (1) {
- char message[255] = "Hello AVK!";
- s_send(publisher, message);
- }
- zmq_close(publisher);
- 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