0
I am trying to connect to a bitcoin node using the ZMQ library for Java. the problem is that when I try to receive a response the code remains frozen. Returns nothing.
This is my code:
public class CBETest {
private static final String TEST_URL = "obelisk.airbitz.co";
public static void main(String[] args) {
System.out.println("\t--- ZMQ ---");
Ctx c = zmq.ZMQ.createContext();
SocketBase s = c.createSocket(zmq.ZMQ.ZMQ_DEALER);
zmq.ZMQ.connect(s, "tcp://"+TEST_URL+":9091");
System.out.println("Connected!");
int sent = zmq.ZMQ.send(s, "blockchain.fetch_last_height", 0);
System.out.println("Sent: " + sent);
Msg msg = zmq.ZMQ.recv(s, 0);
System.out.println("Response " + Arrays.toString(msg.data()));
}
}
The code freezes in the line Msg msg = zmq.ZMQ.recv(s, 0);. I am using the calls described here for the full node implemetation. Thanks in advance!
Double check, if you have started bitcoind with
-zmqpubhashtx=tcp://<ip>:<port>and or-zmqpubhashblock=tcp://<ip>:<port>. – Jonas Schnelli – 2016-01-04T12:17:10.850Also check https://github.com/bitcoin/bitcoin/blob/master/qa/rpc-tests/zmq_test.py and keep in mind: zmq.ZMQ.recv does block your thread until bitcoind sends a block or tx.
– Jonas Schnelli – 2016-01-04T12:17:43.630