Linux下执行runExampleClientRPCJava任务失败:无法连接服务器
Answer
I’ve helped troubleshoot this exact issue many times with CorDapp developers—this is one of the most common RPC connection problems, and it almost always boils down to a few straightforward causes. Here’s a breakdown of what’s likely going wrong, how to fix it, and what other users have reported:
Common Causes & Fixes
1. Your CorDapp Node Isn’t Running (or Failed to Start)
The RPC client can’t connect if the target node isn’t up and listening for RPC requests.
- Check if the node is running: Run
ps aux | grep cordain your terminal—you should see a process for your CorDapp node. - Verify node startup: Check your node’s log file (usually in
logs/node-<party-name>.log) for a line likeListening on address localhost:10006 for RPC connections. If you don’t see this, the node failed to start properly—look earlier in the logs for errors (like missing dependencies or misconfigurednode.conf). - Restart the node: If it’s not running, start it with
./gradlew runNodes(from the project root) and wait for the "RPC listening" log line before running the client.
2. Mismatched RPC Address/Port Between Client & Node
The client might be trying to connect to the wrong port or address.
- Check node’s RPC port: Open your node’s
node.conffile and look for therpcSettingssection—this defines the address and port the node uses for RPC (default islocalhost:10006for PartyA). - Validate client configuration: Open
java-source/src/main/java/com/example/client/ExampleClientRPC.javaand check theCordaRPCClientinitialization. Make sure theNetworkHostAndPortmatches exactly what’s in your node’srpcSettings. For example:
A common mistake is using the node’s P2P port (usually 10005) instead of the RPC port.// Correct example (matches default node config) CordaRPCClient client = new CordaRPCClient(new NetworkHostAndPort("localhost", 10006));
3. Linux Firewall/Security Group Blocking the RPC Port
Linux firewalls (like ufw or firewalld) often block incoming/outgoing connections on non-standard ports like the CorDapp RPC port.
- Test with firewall disabled: Temporarily stop your firewall to rule this out. For
firewalld, runsudo systemctl stop firewalld; forufw, runsudo ufw disable. Then try running the client again. - Allow the RPC port permanently: If this fixes the issue, add a rule to allow traffic on the RPC port. For
firewalld:
Forsudo firewall-cmd --add-port=10006/tcp --permanent sudo firewall-cmd --reloadufw:sudo ufw allow 10006/tcp
4. Missing RPC Authentication Credentials
If your node is configured to require RPC username/password authentication, the client will fail to connect without providing these details.
- Check node’s RPC user config: Look in
node.conffor therpcUserssection—this lists authorized users and their permissions. - Update client code to include auth: Modify the client’s
start()call to include the username and password fromnode.conf:CordaRPCConnection connection = client.start("your-rpc-username", "your-rpc-password");
Community Context
Yes, this is a super common issue reported by CorDapp developers on community forums and Stack Overflow. Most users resolve it by:
- Realizing they forgot to start their nodes before running the client
- Fixing a port mismatch between client code and node config
- Unblocking the RPC port in their Linux firewall
A few users also ran into issues where their node’s node.conf had typos in the rpcSettings section, causing the node to not bind to the expected RPC port. Always double-check that config file if you’ve ruled out the other causes!
内容的提问来源于stack exchange,提问作者C. Andrews

