More tidying up of existing text

pull/3109/head
Lisa Carey 10 years ago
parent 31d143ce07
commit 0af588a9cf
  1. 42
      README.md

@ -211,7 +211,7 @@ which contains (along with some other useful code):
} }
``` ```
- _stub_ classes that clients can use to talk to a `Greetings` server. - _stub_ classes that clients can use to talk to a `Greetings` server. As you can see, they also implement the `Greetings` interface.
```java ```java
public static class GreetingsStub extends public static class GreetingsStub extends
@ -236,7 +236,7 @@ Our server application has two classes:
[GreetingsImpl.java](java/src/main/java/ex/grpc/GreetingsImpl.java). [GreetingsImpl.java](java/src/main/java/ex/grpc/GreetingsImpl.java).
- a server that hosts the service implementation and allows access over the - a server that hosts the service implementation and allows access over the
network: [GreetingsServer.java](src/main/java/ex/grpc/GreetingsServer.java). network: [GreetingsServer.java](java/src/main/java/ex/grpc/GreetingsServer.java).
#### Service implementation #### Service implementation
@ -245,7 +245,7 @@ actually implements our GreetingService's required behaviour.
As you can see, the class `GreetingsImpl` implements the interface As you can see, the class `GreetingsImpl` implements the interface
`GreetingsGrpc.Greetings` that we [generated](#generating) from our proto `GreetingsGrpc.Greetings` that we [generated](#generating) from our proto
[IDL](src/main/proto/helloworld.proto) by implementing the method `hello`: [IDL](java/src/main/proto/helloworld.proto) by implementing the method `hello`:
```java ```java
public void hello(Helloworld.HelloRequest req, public void hello(Helloworld.HelloRequest req,
@ -276,11 +276,13 @@ finished dealing with this RPC.
#### Server implementation #### Server implementation
[GreetingsServer.java](src/main/java/ex/grpc/GreetingsServer.java) shows the [GreetingsServer.java](java/src/main/java/ex/grpc/GreetingsServer.java) shows the
other main feature required to provde the gRPC service; making the service other main feature required to provide a gRPC service; making the service
implementation available from the network. implementation available from the network.
```java ```java
private ServerImpl server;
...
private void start() throws Exception { private void start() throws Exception {
server = NettyServerBuilder.forPort(port) server = NettyServerBuilder.forPort(port)
.addService(GreetingsGrpc.bindService(new GreetingsImpl())) .addService(GreetingsGrpc.bindService(new GreetingsImpl()))
@ -291,9 +293,9 @@ implementation available from the network.
``` ```
- it provides a class `GreetingsServer` that holds a `ServerImpl` that will run the server The `GreetingsServer` class has a `ServerImpl` member that actually runs the server. To create an appropriate `ServerImpl`, we use a special `ServerBuilder` class (in this case a `NettyServerBuilder`) in the `GreetingsServer`'s `start` method, binding the `GreetingsService` implementation that we created to a port. Then we start the server running: the server is now ready to receive requests from `Greetings` service clients on our specified port. We'll cover how all this works in a bit more detail in our language-specific documentation.
- in the `start` method, `GreetingServer` binds the `GreetingsService` implementation to a port and begins running it
- there is also a `stop` method that takes care of shutting down the service and cleaning up when the program exits `GreetingsServer` also has a `stop` method that takes care of shutting down the service and cleaning up when the program exits.
#### Build it #### Build it
@ -308,16 +310,16 @@ We'll look at using a client to access the server in the next section.
<a name="client"></a> <a name="client"></a>
### Writing a client ### Writing a client
Client-side gRPC is pretty simple. In this step, we'll use the generated code to write a simple client that can access the `Greetings` server we created in the previous section. You can see the complete client code in [GreetingsClient.java](src/main/java/ex/grpc/GreetingsClient.java). Client-side gRPC is pretty simple. In this step, we'll use the generated code to write a simple client that can access the `Greetings` server we created in the [previous section](#server). You can see the complete client code in [GreetingsClient.java](java/src/main/java/ex/grpc/GreetingsClient.java).
Again, we're not going to go into much detail about how to implement a client - we'll leave that for the tutorial. Again, we're not going to go into much detail about how to implement a client - we'll leave that for the tutorial.
#### Connecting to the service #### Connecting to the service
. The internet address First let's look at how we connect to the `Greetings` server. The internet address
is configured in the client constructor. gRPC Channel is the abstraction over is configured in the client constructor. gRPC `Channel` provides the abstraction layer over
transport handling; its constructor accepts the host name and port of the transport handling; its constructor accepts the host name and port of the
service. The channel in turn is used to construct the Stub. service. The channel in turn is used to construct the stub instance.
```java ```java
@ -335,11 +337,11 @@ service. The channel in turn is used to construct the Stub.
#### Obtaining a greeting #### Obtaining a greeting
The greet method uses the stub to contact the service and obtain a greeting. The `greet()` method uses the stub to contact the service and obtain a greeting.
It: In the method we:
- constructs a request - construct and fill in a `HelloRequest` to send to the stub
- obtains a reply from the stub - get a reply from the stub
- prints out the greeting - print out the greeting
```java ```java
@ -375,7 +377,7 @@ line.
#### Build the client #### Build the client
This is the same as before: our client and server are part of the same maven This is the same as building the server: our client and server are part of the same maven
package so the same command builds both. package so the same command builds both.
``` ```
@ -407,6 +409,10 @@ and in another terminal window confirm that it receives a message.
$ ./run_greetings_client.sh $ ./run_greetings_client.sh
``` ```
### Adding another client
###TODO: Section on Go client for same server

Loading…
Cancel
Save