Java Client examples in developer's guide

+2 votes

I am trying to follow the developers guide to connect multichain via java client. There are 2 examples given (please check snapshot in below first link). "MultiChainJavaAPI" does not have main class while other "Multichain Client Java" (part-2) is giving 'connection refused' (see second link below). Plz hep?.

 

https://drive.google.com/file/d/1aBS6D1vdtWXPWJuBU2dOkbkRuJcv3L1m/view?usp=sharing

https://drive.google.com/file/d/1SZscLaVihiaqvDzwq-nLIMiVR1kqJpKI/view?usp=sharing

 

 

asked Jan 17, 2022 by Adnan UL Haque

1 Answer

+1 vote

A "connection refused" error is usually because the node is running on a different computer to the application, and the node has not been configured to allow incoming API requests from that other computer. Please search this Q&A forum for the word rpcallowip to see more information.

answered Jan 18, 2022 by MultiChain
Infact, my java client is on the same computer. Please advice accordingly.
Have you checked multichain is running by using the command-line, e.g. just to get the response from a command like getinfo?
I started working on java client after thoroughly checking multichain CLI functionality. You should again review my initial question whihc is specifically asking about some thing missing in official mutichain guidelines. Anyhow, issue is fixed and I am pasting here for other's to benefit ...


===============================================
package multichain;


import multichain.command.CommandElt;
import multichain.command.CommandManager;
import multichain.command.RuntimeParameters;



public class dbt558 {
    public static void main(String[] args) {
        Object getInfo;

        RuntimeParameters Param=new RuntimeParameters();
        Param.setDatadir("C:\\Users\\adnan\\AppData\\Roaming\\MultiChain\\");
        Param.setRpcport("6756");

        CommandManager CM=new CommandManager("localhost", "6756", "multichainrpc", "9UhZQQy8ZgaVZZbHtJkcXRVUdqzPAsLk9DPNCVAJy1UJ");

        try {
            

            getInfo=CM.invoke(CommandElt.GETINFO);

            System.out.println(getInfo);
        } catch (Exception e) {
            System.out.println(e);    
        }
            
        
    }
}


==========================================

above java client is connected to following blockchian network.

======================================
$ ./multichaind tutchain -daemon
Other nodes can connect to this node using:
multichaind tutchain@169.254.97.111:6757

This host has multiple IP addresses, so from some networks:
multichaind tutchain@169.254.143.247:6757
multichaind tutchain@192.168.100.9:6757

Listening for API requests on port 6756 (local only - see rpcallowip setting)

Node ready.

============================================

user/password used in above java client from multichain.conf file (below printout)

=================================================
adnan@MSI MINGW64 ~/AppData/Roaming/MultiChain/tutchain
$ cat multichain.conf
rpcuser=multichainrpc
rpcpassword=9UhZQQy8ZgaVZZbHtJkcXRVUdqzPAsLk9DPNCVAJy1UJ

adnan@MSI MINGW64 ~/AppData/Roaming/MultiChain/tutchain
$ pwd
/c/Users/adnan/AppData/Roaming/MultiChain/tutchain

adnan@MSI MINGW64 ~/AppData/Roaming/MultiChain/tutchain
$
==================================================
Thanks for the update and sharing the solutions. FYI these are third-party libraries so we are not so familiar with them.
...