gRPC Android客户端异常io.grpc.StatusRuntimeException:无法使用

时间:2018-10-31 12:44:26

标签: react-native-android grpc grpc-java

我有一个在tcp://localhost:50051上本地运行的GO服务器和一个React Native模块Android / iOS。

iOS模块正常工作,当我从android虚拟设备尝试时,会引发以下异常。

    io.grpc.StatusRuntimeException: UNAVAILABLE
                          at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:230)
                          at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:211)
                          at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:144)
                          at 
... callig my stub method ...
                          at android.os.AsyncTask$2.call(AsyncTask.java:333)
        I/System.out:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                          at java.lang.Thread.run(Thread.java:764)
                      Caused by: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 50051) from /:: (port 51916): connect failed: ECONNREFUSED (Connection refused)
                          at libcore.io.IoBridge.connect(IoBridge.java:138)
                          at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:129)
                          at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:356)
                          at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
                          at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
                          at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
                          at java.net.Socket.connect(Socket.java:616)
                          at java.net.Socket.connect(Socket.java:565)
                          at java.net.Socket.<init>(Socket.java:445)
                          at java.net.Socket.<init>(Socket.java:248)
                          at io.grpc.okhttp.OkHttpClientTransport$1.run(OkHttpClientTransport.java:419)
                          at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:154)
                        ... 3 more
                      Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
                          at libcore.io.Linux.connect(Native Method)
                          at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:126)
                          at libcore.io.IoBridge.connectErrno(IoBridge.java:152)
                          at libcore.io.IoBridge.connect(IoBridge.java:130)
                        ... 14 more

10.0.2.2:8081上运行的AVD。

1 个答案:

答案 0 :(得分:1)

在Android模拟器上运行时,localhost是Android设备。您需要使用计算机的IP /主机名。