Created
January 5, 2019 21:55
ZMQ publisher with ZMQ_CONFLATE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <unistd.h> | |
#include "zmq.hpp" | |
static const char *addr = "tcp://*:1337"; | |
void pub_loop(void) | |
{ | |
zmq::context_t ctx; | |
zmq::socket_t so(ctx, ZMQ_PUB); | |
int conflate_opt = 1; | |
so.setsockopt(ZMQ_CONFLATE, &conflate_opt, sizeof(conflate_opt)); | |
so.bind(addr); | |
std::cerr << "zmq pub socket bound on " << addr << std::endl; | |
std::vector<char> buf(1024*1024); | |
while (true) { | |
so.send(buf.data(), buf.size()); | |
sleep(1); | |
} | |
} | |
int main(int argc, char **argv) | |
{ | |
if (argc > 2) { | |
std::cerr << "usage: " << argv[0] << " [endpoint_url]" << std::endl; | |
exit(EXIT_FAILURE); | |
} else if (argc == 2) { | |
addr = argv[1]; | |
} | |
try { | |
pub_loop(); | |
} catch (zmq::error_t &err) { | |
std::cerr << "zmq error: " << err.what() << std::endl; | |
exit(EXIT_FAILURE); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment