java-sdk citaj service send()超时

在本机的虚拟机环境中搭建了四个节点的cita区块链网络,利用java-sdk实现交易,但是在执行String txHash = service.appSendRawTransaction(rawTx).send().getSendTransactionResult().getHash();会报超时,好像搭建的cita网络环境没有启动成功,但是利用cita-remix可以成功部署合约,请问该如何定位问题做debug。

启动之后,先验证一下相关的进程是否正常启动 https://docs.citahub.com/zh-CN/next/cita/getting-started/run-cita#验证-cita-是否运行正常

然后可以用curl查询块高 https://docs.citahub.com/zh-CN/next/cita/rpc-guide/rpc#blocknumber
看出块是否正常。

4个节点,和28个进程都有
在本地操作都是可以的,利用cita-cli rpc blockNumber可以查询出块高度。
但是在本地利用curl命令调用jsonrpc就会失败

补充一下,利用curl也可以查询出区块高度,但是在宿主机上调用还是超时:
【关键代码】
CITAj service = CITAj.build(new HttpService(“https://172.16.10.43:1337”));
Random random = new Random(System.currentTimeMillis());
String nonce = String.valueOf(Math.abs(random.nextLong()));
Transaction tx = new Transaction(contractAddr, nonce, 10000000L, 0l, 2, BigInteger.ONE, “0”, funcData);
String rawTx = tx.sign(privateKey);

    String txHash =  service.appSendRawTransaction(rawTx).send().getSendTransactionResult().getHash();

【异常如下】

java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_271]
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:81) ~[na:1.8.0_271]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476) ~[na:1.8.0_271]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218) ~[na:1.8.0_271]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200) ~[na:1.8.0_271]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:162) ~[na:1.8.0_271]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394) ~[na:1.8.0_271]
at java.net.Socket.connect(Socket.java:606) ~[na:1.8.0_271]
at okhttp3.internal.platform.Platform.connectSocket(Platform.java:130) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:263) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:183) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:169) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[okhttp-3.14.9.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[okhttp-3.14.9.jar:na]
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229) ~[okhttp-3.14.9.jar:na]
at okhttp3.RealCall.execute(RealCall.java:81) ~[okhttp-3.14.9.jar:na]
at com.citahub.cita.protocol.http.HttpService.performIO(HttpService.java:102) ~[core-20.2.0.jar:na]
at com.citahub.cita.protocol.Service.send(Service.java:34) ~[core-20.2.0.jar:na]
at com.citahub.cita.protocol.core.Request.send(Request.java:69) ~[core-20.2.0.jar:na]
at com.example.demo.ctl.Test.index(Test.java:43) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_271]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_271]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_271]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_271]

按照你的描述,1337端口是开在虚拟机上,如果要在宿主机上访问,需要设置一下端口映射吧?