Android java-grpc客户端到python-grpc服务器

时间:2020-05-22 13:33:43

标签: java android grpc-java grpc-python

我遇到了android java-grpc问题,它可以连接到GRPC服务器(不超时),但是声称服务不可用。我已经在两台不同的机器上测试了从python到python的服务器,它们都可以连接,但是Android抛出异常。下面是我用来连接的方法和完整的堆栈跟踪。看起来conscrypt引擎是个问题,但是我可以全神贯注于解决方案。

    public LoginDataSource() {
    }

    public Result<LoggedInUser> login(String username, String password) {
        ManagedChannel commChannel = ManagedChannelBuilder.forAddress(server_string,55051).build();
        LoginServiceGrpc.LoginServiceBlockingStub blockingStub = LoginServiceGrpc.newBlockingStub(commChannel);
        GrpcServerComm.LoginData loginData = GrpcServerComm.LoginData.newBuilder().setUsername(username).setPassword(password).build();

        try
        {
            GrpcServerComm.LoginRequest serverResponse = blockingStub.getLogin(loginData);
            long serverResponseVal = serverResponse.getResponseVal();
            LoggedInUser activeUser = new LoggedInUser(username,username);

            return new Result.Success<>(activeUser);
        }
        catch (StatusRuntimeException e)
        {
            Log.d("Error", e.getMessage());
            return new Result.Error(new IOException("Error logging in", e));

        }

    }
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.equinox.openeyes, PID: 4883
    io.grpc.StatusRuntimeException: UNAVAILABLE
        at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:244)
        at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:225)
        at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:142)
        at com.equinox.openeyes.LoginServiceGrpc$LoginServiceBlockingStub.getLogin(LoginServiceGrpc.java:168)
        at com.equinox.openeyes.data.LoginDataSource.login(LoginDataSource.java:33)
        at com.equinox.openeyes.data.LoginRepository.login(LoginRepository.java:48)
        at com.equinox.openeyes.ui.login.LoginViewModel.login(LoginViewModel.java:34)
        at com.equinox.openeyes.ui.login.LoginActivity$5.onClick(LoginActivity.java:116)
        at android.view.View.performClick(View.java:7350)
        at android.view.View.performClickInternal(View.java:7327)
        at android.view.View.access$3600(View.java:807)
        at android.view.View$PerformClick.run(View.java:28166)
        at android.os.Handler.handleCallback(Handler.java:907)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7464)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)
     Caused by: javax.net.ssl.SSLException: Unable to parse TLS packet header
        at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:797)
        at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:737)
        at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:702)
        at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.processDataFromSocket(ConscryptEngineSocket.java:810)
        at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.access$100(ConscryptEngineSocket.java:683)
        at com.android.org.conscrypt.ConscryptEngineSocket.doHandshake(ConscryptEngineSocket.java:235)
        at com.android.org.conscrypt.ConscryptEngineSocket.startHandshake(ConscryptEngineSocket.java:214)
        at io.grpc.okhttp.OkHttpProtocolNegotiator.negotiate(OkHttpProtocolNegotiator.java:92)
        at io.grpc.okhttp.OkHttpProtocolNegotiator$AndroidNegotiator.negotiate(OkHttpProtocolNegotiator.java:147)
        at io.grpc.okhttp.OkHttpTlsUpgrader.upgrade(OkHttpTlsUpgrader.java:63)
        at io.grpc.okhttp.OkHttpClientTransport$4.run(OkHttpClientTransport.java:571)
        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

1 个答案:

答案 0 :(得分:0)

发现了问题:服务器正在使用不安全的通道,正在尝试建立SSL连接。