Created
January 16, 2017 13:46
-
-
Save andr1972/cb5f3fc89f851a93be271d3a886153e4 to your computer and use it in GitHub Desktop.
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
/* | |
using: http://zeromq.org/ | |
see https://github.com/bitcoin/bitcoin/blob/master/contrib/zmq/zmq_sub.py | |
first call: bitcoind -zmqpubhashtx=tcp://127.0.0.1:28332 -zmqpubrawtx=tcp://127.0.0.1:28332 & | |
*/ | |
#include <stdexcept> | |
#include <iostream> | |
#include <cstdlib> | |
#include <cstring> | |
#include <vector> | |
#include <zmq.h> | |
int main(int argc, char **argv) { | |
void *context = zmq_ctx_new(); | |
void *socket = zmq_socket(context, ZMQ_SUB); | |
zmq_setsockopt(socket, ZMQ_SUBSCRIBE, "hashblock", 9); | |
zmq_setsockopt(socket, ZMQ_SUBSCRIBE, "hashtx", 6); | |
zmq_setsockopt(socket, ZMQ_SUBSCRIBE, "rawblock", 8); | |
zmq_setsockopt(socket, ZMQ_SUBSCRIBE, "rawtx", 5); | |
zmq_connect(socket, "tcp://127.0.0.1:28332"); | |
while (true) | |
{ | |
std::vector<std::string> msg_parts; | |
char optbuf[256]; | |
size_t optlen; | |
do { | |
char buf[80]; | |
zmq_recv(socket, buf, 80, 0); | |
printf("%s\n", buf); | |
// Read data from msg_part, and stick it into a std::string then put that into the part list | |
//msg_parts.push_back(std::string(static_cast<char*>(msg_part.data()), msg_part.size())); | |
zmq_getsockopt(socket, ZMQ_RCVMORE, optbuf, &optlen); | |
} while (optlen==0); | |
printf("end\n"); | |
} | |
zmq_ctx_shutdown(context); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment