I'm programming a Bitcoin miner that mines in a pool using the stratum protocol (see documentation here.
The stratum protocol uses JSON-RPC 2.0 as its encoding and according to the JSON-RPC 2.0 specification. I should use sockets to create a connection to the pool.
My problem is that I don't seem to be able to receive a response back from the pool. JSON-RPC 2.0 states that for every Request object that I send, I must receive a response back.
Here is my code:
public static void main(String[] args) { connectToPool("stratum.slushpool.com", 3333); } static void connectToPool(String host, int port) { try { InetAddress address = InetAddress.getByName(host); out.println("Atempting to connect to " + address.toString() + " on port " + port + "."); socket = new Socket(address, port); String message1 = "{\"jsonrpc\" : \"2.0\", \"id\": 1, \"method\": \"mining.subscribe\", \"params\": []}"; PrintWriter output = new PrintWriter(socket.getOutputStream(), true); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); output.write((message1 + "\\n")); out.println(input.readLine());//Hangs here. } catch (IOException e) { out.println(e.getMessage()); out.println("Error. Can't connect to Pool."); System.exit(-2);
}
}