xref: /aosp_15_r20/external/grpc-grpc-java/examples/example-hostname/README.md (revision e07d83d3ffcef9ecfc9f7f475418ec639ff0e5fe)
1*e07d83d3SAndroid Build Coastguard WorkergRPC Hostname Example
2*e07d83d3SAndroid Build Coastguard Worker=====================
3*e07d83d3SAndroid Build Coastguard Worker
4*e07d83d3SAndroid Build Coastguard WorkerThe hostname example is a Hello World server whose response includes its
5*e07d83d3SAndroid Build Coastguard Workerhostname. It also supports health and reflection services. This makes it a good
6*e07d83d3SAndroid Build Coastguard Workerserver to test infrastructure, like load balancing.
7*e07d83d3SAndroid Build Coastguard Worker
8*e07d83d3SAndroid Build Coastguard WorkerThe example requires grpc-java to already be built. You are strongly encouraged
9*e07d83d3SAndroid Build Coastguard Workerto check out a git release tag, since there will already be a build of grpc
10*e07d83d3SAndroid Build Coastguard Workeravailable. Otherwise you must follow [COMPILING](../../COMPILING.md).
11*e07d83d3SAndroid Build Coastguard Worker
12*e07d83d3SAndroid Build Coastguard Worker### Build the example
13*e07d83d3SAndroid Build Coastguard Worker
14*e07d83d3SAndroid Build Coastguard Worker1. Build the hello-world example client. See [the examples README](../README.md)
15*e07d83d3SAndroid Build Coastguard Worker
16*e07d83d3SAndroid Build Coastguard Worker2. Build this server. From the `grpc-java/examples/examples-hostname` directory:
17*e07d83d3SAndroid Build Coastguard Worker```
18*e07d83d3SAndroid Build Coastguard Worker$ ../gradlew installDist
19*e07d83d3SAndroid Build Coastguard Worker```
20*e07d83d3SAndroid Build Coastguard Worker
21*e07d83d3SAndroid Build Coastguard WorkerThis creates the script `build/install/hostname-server/bin/hostname-server` that
22*e07d83d3SAndroid Build Coastguard Workerruns the example.
23*e07d83d3SAndroid Build Coastguard Worker
24*e07d83d3SAndroid Build Coastguard WorkerTo run the hostname example, run:
25*e07d83d3SAndroid Build Coastguard Worker
26*e07d83d3SAndroid Build Coastguard Worker```
27*e07d83d3SAndroid Build Coastguard Worker$ ./build/install/hostname-server/bin/hostname-server
28*e07d83d3SAndroid Build Coastguard Worker```
29*e07d83d3SAndroid Build Coastguard Worker
30*e07d83d3SAndroid Build Coastguard WorkerAnd in a different terminal window run the hello-world client:
31*e07d83d3SAndroid Build Coastguard Worker
32*e07d83d3SAndroid Build Coastguard Worker```
33*e07d83d3SAndroid Build Coastguard Worker$ ../build/install/examples/bin/hello-world-client
34*e07d83d3SAndroid Build Coastguard Worker```
35*e07d83d3SAndroid Build Coastguard Worker
36*e07d83d3SAndroid Build Coastguard Worker### Maven
37*e07d83d3SAndroid Build Coastguard Worker
38*e07d83d3SAndroid Build Coastguard WorkerIf you prefer to use Maven:
39*e07d83d3SAndroid Build Coastguard Worker1. Build the hello-world example client. See [the examples README](../README.md)
40*e07d83d3SAndroid Build Coastguard Worker
41*e07d83d3SAndroid Build Coastguard Worker2. Run in this directory:
42*e07d83d3SAndroid Build Coastguard Worker```
43*e07d83d3SAndroid Build Coastguard Worker$ mvn verify
44*e07d83d3SAndroid Build Coastguard Worker$ # Run the server (from the examples-hostname directory)
45*e07d83d3SAndroid Build Coastguard Worker$ mvn exec:java -Dexec.mainClass=io.grpc.examples.hostname.HostnameServer
46*e07d83d3SAndroid Build Coastguard Worker$ # In another terminal run the client (from the examples directory)
47*e07d83d3SAndroid Build Coastguard Worker$ cd ..
48*e07d83d3SAndroid Build Coastguard Worker$ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworld.HelloWorldClient
49*e07d83d3SAndroid Build Coastguard Worker```
50*e07d83d3SAndroid Build Coastguard Worker
51*e07d83d3SAndroid Build Coastguard Worker### Bazel
52*e07d83d3SAndroid Build Coastguard Worker
53*e07d83d3SAndroid Build Coastguard WorkerIf you prefer to use Bazel, run from the `grpc-java/examples` directory:
54*e07d83d3SAndroid Build Coastguard Worker```
55*e07d83d3SAndroid Build Coastguard Worker$ bazel build :hello-world-client example-hostname:hostname-server
56*e07d83d3SAndroid Build Coastguard Worker$ # Run the server
57*e07d83d3SAndroid Build Coastguard Worker$ ./bazel-bin/example-hostname/hostname-server
58*e07d83d3SAndroid Build Coastguard Worker$ # In another terminal run the client
59*e07d83d3SAndroid Build Coastguard Worker$ ./bazel-bin/hello-world-client
60*e07d83d3SAndroid Build Coastguard Worker```
61