我正在尝试在提供者和消费者进程之间建立一个与平台无关的通信渠道。发现 grpc + protobuf 是一个不错的选择。
是否有在 Android 上运行的 GRPC 服务器(Java/C++)的示例或实现?我正在按照 grpc java 服务器示例来实现服务器 i
private class GrpcServerTask extends AsyncTask<Void, Void, String>{
@Override
protected void onPreExecute() {
}
@Override
protected String doInBackground(Void... params) {
int port = 50051;
Server server;
try {
server = ServerBuilder.forPort(port)
.addService(new GreeterImpl())
.build()
.start();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
private class GreeterImpl extends GreeterGrpc.GreeterImplBase {
@Override
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + req.getName()).build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
}
我不断收到错误
io.grpc.ManagedChannelProvider$ProviderNotFoundException: No functional server found. Try adding a dependency on the grpc-netty artifact
on executing new GrpcServerTask().execute();
谢谢