2
I call:
bitcoind -zmqpubrawtx=ipc:///tmp/bitcoind.tx.raw
or even call:
bitcoind -zmqpubhashtx=tcp://127.0.0.1:9050 - zmqpubrawtx=ipc:///tmp/bitcoind.tx.raw
where 9050 is port from bicoin config. File /tmp/bitcoind.tx.raw is empty i has lenght=0 How can I dump transactions? I read, this file is websocket and I must subscribe to it:
Client side, then, the ZeroMQ subscriber socket must have the ZMQ_SUBSCRIBE
option set to one or either of these prefixes (for instance, just hash);
without doing so will result in no messages arriving. Please see
contrib/zmq/zmq_sub.py for a working example."
How can I read it programically? I try create c++ program from Python sources and https://github.com/plq/zmq.git
include
#include <iostream>
#include <cstdlib>
#include <cstring>
#include "zmq.hpp"
using std::cout;
using std::endl;
void recv_multipart(zmq::socket_t &socket) {
int64_t more=-1;
size_t more_size = sizeof (more);
while(more) {
zmq::message_t response;
socket.recv(&response);
std::string response_str((const char *)response.data(),
response.size());
cout << response_str << endl;
socket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
}
}
int main(int argc, char **argv) {
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_SUB);
socket.setsockopt(ZMQ_SUBSCRIBE, "hashblock");
socket.setsockopt(ZMQ_SUBSCRIBE, "hashtx");
socket.setsockopt(ZMQ_SUBSCRIBE, "rawblock");
socket.setsockopt(ZMQ_SUBSCRIBE, "rawtx");
//socket.connect(/*argv[2]*/"ipc:///tmp/bitcoind.tx.raw");
socket.connect("tcp://127.0.0.1:28332");
size_t arg_len= std::strlen("Unknown");
zmq::message_t message(arg_len);
std::memcpy(message.data(), "Unknown", arg_len);
socket.send(message);
recv_multipart(socket);
return 0;
}
Can I use https://github.com/zaphoyd/websocketpp ?
– Saku – 2017-01-09T12:58:05.227It is a ZMQ socket. It is not a Websocket. Socket here refers to the old UNIX concept of a bidirectional interprocess pipe represented. ZMQ is a particular network protocol for publishing/subscribing to events. – Pieter Wuille – 2017-01-09T13:19:08.347
soc=socket(PF_INET, SOCK_STREAM, 0); ? , sai.sin_family=PF_INET; sai.sin_port=port; ?//how subscribe and read it? I need source code – Saku – 2017-01-09T13:32:14.793
You need libzmq. – Pieter Wuille – 2017-01-09T14:02:38.350
I have compiled https://github.com/plq/zmq and this say: zmq <SOCKET_TYPE> <URI> <MSG>; how is SOCKET_TYPE,URI and MSG for this case?
– Saku – 2017-01-09T14:18:28.587zmq REQ ipc:///tmp/bitcoind.tx.raw ZMQ_SUBSCRIBE nor zmq REQ tcp://127.0.0.1:28332 ZMQ_SUBSCRIBE nothing gets – Saku – 2017-01-09T14:30:06.767
That shell wrapper does not support SUBSCRIBE sockets. – Pieter Wuille – 2017-01-09T14:51:22.047
I used Bitcoin Python example: sudo apt-get install python-zmq / python zmq_sub.py; but in this case program waits and no message to console – Saku – 2017-01-09T16:19:30.817