How to use socket with JSON-RPC?

0

I have a class in which I am trying to send a request to the server and receive a json response to handle, but nothing happens.

I do not know if I sent the request correctly or when it was time to get it.

Follow the code:

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class RemoteSocket {

        void getJsonSocket() {


            try {
                Socket socket = new Socket("192.168.0.102", 3333);

                String jsonRequest = "{\"id\":0,\"jsonrpc\":\"2.0\",\"method\":\"miner_getstat1\"}";

                ObjectInputStream input = new ObjectInputStream(socket.getInputStream());

                ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream());

                //Envia requisição para o servidor
               output.writeChars(jsonRequest);
               output.flush();
               output.close();

               //Realiza a leitura da resposta do servidor
                System.out.println(input.readChar());


            } catch (IOException e) {
                e.printStackTrace();
            }



        }
    }

Another problem is that it is jumping the "ObjectOutputStream", does not get to execute the instruction, for in the ObjectInputStream, I was debugging and I realized it.

The return example is as follows:

{"result": ["9.3 - ETH", "21", "182724;51;0", "30502;30457;30297;30481;30479;30505", "0;0;0", "off;off;off;off;off;off", "53;71;57;67;61;72;55;70;59;71;61;70", "eth-eu1.nanopool.org:9999", "0;0;0;0"]}
    
asked by anonymous 03.11.2018 / 21:02

0 answers