gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:35:32 30 4
gpt4 key购买 nike

我遇到了 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)

最佳答案

发现问题:服务器正在使用不安全的 channel ,正在尝试 SSL 连接。

关于java - Android java-grpc 客户端到 python-grpc 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61956278/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com