Not able to connect to MultiChain Node

+2 votes
1. Please  find my sample code:-

 private static JSONObject invokeRPC() {
  @SuppressWarnings("deprecation")
  
 
  
  DefaultHttpClient httpclient = new DefaultHttpClient();

 

  System.out.println("invokeRPC");
  JSONObject json = new JSONObject();
  
  
  JSONObject responseJsonObj = null;
  try {
   httpclient.getCredentialsProvider().setCredentials(
     new AuthScope("172.17.0.2", 7742),
     new UsernamePasswordCredentials("multichainrpc",
       "Cojw4D6uo9fLnKdGLj7qH9WNqLftqXi15hWLhXt9q2HC"));
   StringEntity myEntity = new StringEntity(json.toJSONString());
   System.out.println(json.toString());
   HttpPost httppost = new HttpPost(
     "http://multichainrpc:Cojw4D6uo9fLnKdGLj7qH9WNqLftqXi15hWLhXt9q2HC@172.17.0.2:7742");
   httppost.setEntity(myEntity);

 

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

 

   System.out.println("----------------------------------------");
   System.out.println(response.getStatusLine());
   if (entity != null) {
    System.out.println("Response content length: "
      + entity.getContentLength());
    // System.out.println(EntityUtils.toString(entity));
   }
   JSONParser parser = new JSONParser();
   responseJsonObj = (JSONObject) parser.parse(EntityUtils
     .toString(entity));
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return responseJsonObj;
 }

2. My node details are below:-

MultiChain Core Daemon build 1.0 alpha 21 protocol 10005

 

MultiChain server starting
Looking for genesis block...
Genesis block found
New users can connect to this node using
multichaind chain10@172.17.0.2:7743

 

Node started
root@0cfea1e2478d:/tmp/multichain-1.0-alpha-21# cat ~/.multichain/chain1/multichain.conf
rpcuser=multichainrpc
rpcpassword=6SvszQi9gbWU816wg7XYawxrZXp6FMKp4B9k6fchQ6vG
rpcallowip=172.17.0.2/172.17.0.3
rpcport=9242
root@0cfea1e2478d:/tmp/multichain-1.0-alpha-21# cat ~/.multichain/chain10/multichain.conf
rpcuser=multichainrpc
rpcpassword=Cojw4D6uo9fLnKdGLj7qH9WNqLftqXi15hWLhXt9q2HC
root@0cfea1e2478d:/tmp/multichain-1.0-alpha-21# grep rpc-port ~/.multichain/chain10/params.dat
default-rpc-port = 7742                 # Default TCP/IP port for incoming JSON-RPC API requests.
root@0cfea1e2478d:/tmp/multichain-1.0-alpha-21#

 

3. I am getting the following exception:-

executing requestPOST http://multichainrpc:Cojw4D6uo9fLnKdGLj7qH9WNqLftqXi15hWLhXt9q2HC@172.17.0.2:7742 HTTP/1.1
java.net.ConnectException: Connection timed out: connect
 at java.net.DualStackPlainSocketImpl.connect0(Native Method)
 at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
 at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
 at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
 at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
 at java.net.PlainSocketImpl.connect(Unknown Source)
 at java.net.SocksSocketImpl.connect(Unknown Source)
 at java.net.Socket.connect(Unknown Source)
 at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
 at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
 at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
 at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
 at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
 at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
 at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
 at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
 at multichain.command.BlockCommandTest.invokeRPC(BlockCommandTest.java:85)
 at multichain.command.BlockCommandTest.main(BlockCommandTest.java:212)

 

Please let me know the resolution for the same. Would be  very helpful.
asked Oct 23, 2017 by Sankaran

1 Answer

+1 vote

It looks like the rpcallowip line of multichain.conf is formatted incorrectly. This field uses CIDR notation – see: https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing

If you want to just allow incoming API connections from those two IP addresses, use two lines as follows:

rpcallowip=172.17.0.2
rpcallowip=172.17.0.3

BTW you have posted lots of passwords here so you should be sure to change them all!

answered Oct 23, 2017 by MultiChain
...