Trying to connect via Java Client

+1 vote

Hi

I'm trying to make a connection with the multichain through a java client.

I tried to use both API as show below however, both show connection error refused.
I'm trying to connect through a client on the server, I tried to run the .jar on own server and the error messages were the same.


I also tried to follow the orientations of the following topics with the same doubts, but had no success. Below as well as station I view the files and params.dat multichain.conf

http://www.multichain.com/qa/362/issue-while-connecting-with-node-using-java-client

http://www.multichain.com/qa/633/connect-multichain-using-json

 

In server multichain.conf: (ip client)

rpcuser=multichainrpc
rpcpassword=XYZ
server=1
rpcallowip=10.20.20.47/255.255.255.0
rpcport=4368

And params.dat

anyone-can-connect = true              # Anyone can connect. Ignored if public-network=true.
anyone-can-send = true                 # Anyone can send. 
anyone-can-receive = true              # Anyone can receive. 
 

API BitcoinRPCClient

https://github.com/cdelargy/BitcoinRPCClient

RPCClient c = new RPCClient();
c.getInfo();

 

public class RPCClient {
    private static final String COMMAND_GET_INFO = "getinfo";

    private JSONObject invokeRPC(String id, String method, List<String> params) {
        DefaultHttpClient httpclient = new DefaultHttpClient();

        JSONObject json = new JSONObject();
        json.put("id", id);
        json.put("method", method);
        if (null != params) {
            JSONArray array = new JSONArray();
            array.addAll(params);
            json.put("params", params);
        }
        JSONObject responseJsonObj = null;
        try {
            httpclient.getCredentialsProvider().setCredentials(new AuthScope("10.20.20.221", 4368),
                    new UsernamePasswordCredentials("multichainrpc", "XYZ"));
            StringEntity myEntity = new StringEntity(json.toJSONString());
            System.out.println(json.toString());
            HttpPost httppost = new HttpPost("http://10.20.20.221:4368");
            httppost.setEntity(myEntity);

            System.out.println("executing request" + httppost.getRequestLine());
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();

            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response content length: " + entity.getContentLength());
            }
            JSONParser parser = new JSONParser();
            responseJsonObj = (JSONObject) parser.parse(EntityUtils.toString(entity));

      (... catch)
    }

    public JSONObject getInfo() {
        JSONObject json = invokeRPC(UUID.randomUUID().toString(), COMMAND_GET_INFO, null);
        return (JSONObject)json.get("result");
    }
}

ERROR:

API Bitcoin-JSON-RPC-Client​

https://bitbucket.org/azazar/bitcoin-json-rpc-client/wiki/Home

public static void balance() throws BitcoinException {
        System.out.println(new BitcoinJSONRPCClient().getBalance());
}

ERROR:

asked Jan 12, 2016 by sola.carol
I can connect locally (in server) through it:

httpclient.getCredentialsProvider().setCredentials(new AuthScope("127.0.0.1", 6716),
new UsernamePasswordCredentials("multichainrpc", "EsnbfGMskLXwNK524nBUnpERghF3PwNRwvFowVU2tZRY"));
       
StringEntity myEntity = new StringEntity(json.toJSONString());
System.out.println(json.toString());
HttpPost httppost = new HttpPost("http://multichainrpc:EsnbfGMskLXwNK524nBUnpERghF3PwNRwvFowVU2tZRY@127.0.0.1:6716");
httppost.setEntity(myEntity);


but only have connection refused on the client

I try set in multichain.conf:

server=1
rpcallowip=10.20.20.47/255.255.255.0
rpcport=6716


And I'm not sure if these commands can cause the restart of the chain

multichain-cli chainName stop
multichaind chainName -daemon

1 Answer

+1 vote
If you are in fact using proper credentials and made the changes to allow the RPC connection, you need to restart the node you want to connect to.

> multichain-cli chainName stop

> multichaind chainName --daemon

Thats the most help I can offer with your stacks setup. I have a working Ruby/Rails implementation running NGINX/Unicorn if you want?

htttp://github.com/padchain/explorer

 

Edit 1: Just saw your rpcallowip comment, it is wrong. It should just be the WAN IP of the server you are trying to connect from. Whatismyip.com if you need to find out.
answered Jan 12, 2016 by mreichardt
I tried restarting the node but errors continue.
also changed the rpcallowip to the server ip...

thank you, but I need a java api
...