前置条件
- JDK 7及以上版本
获取代码
-
Download the repo as a zip file and unzip it, or clone the repo:
$ git clone -b v1.41.0 https://github.com/grpc/grpc-java
-
切换目录
$ cd grpc-java/examples
运行代码
-
编译客户端和服务
$ ./gradlew installDist
-
运行服务
$ ./build/install/examples/bin/hello-world-server 十月 29, 2021 10:35:51 上午 io.grpc.examples.helloworld.HelloWorldServer start 信息: Server started, listening on 50051
-
运行客户端
$ ./build/install/examples/bin/hello-world-client 十月 29, 2021 10:37:27 上午 io.grpc.examples.helloworld.HelloWorldClient greet 信息: Will try to greet world ... 十月 29, 2021 10:37:27 上午 io.grpc.examples.helloworld.HelloWorldClient greet 信息: Greeting: Hello world