content: package helloworld;
  
  import io.grpc.Channel;
  import io.grpc.Grpc;
  import io.grpc.InsecureChannelCredentials;
  import io.grpc.ManagedChannel;
  import io.grpc.StatusRuntimeException;
  import java.util.concurrent.TimeUnit;
  
  /**
  * A simple client that requests a greeting from the {@link HelloWorldServer}.
  */
  public class HelloWorldClient {
    
    private final GreeterGrpc.GreeterBlockingStub blockingStub;
  
    /** Construct client for accessing HelloWorld server using the existing channel. */
    public HelloWorldClient(Channel channel) {
      // 'channel' here is a Channel, not a ManagedChannel, so it is not this code's responsibility to
      // shut it down.
  
      // Passing Channels to code makes code easier to test and makes it easier to reuse Channels.
      blockingStub = GreeterGrpc.newBlockingStub(channel);
    }
  
    /** Say hello to server. */
    public void greet(String name) {
      System.out.println("Will try to greet " + name + " ...");
      HelloRequest request = HelloRequest.newBuilder().setName(name).build();
      HelloReply response;
      try {
        response = blockingStub.sayHello(request);
      } catch (StatusRuntimeException e) {
        System.out.println("RPC failed: {0} " + e.getStatus());
        return;
      }
      System.out.println("Greeting: " + response.getMessage());
    }
  
    /**
    * Greet server. If provided, the first element of {@code args} is the name to use in the
    * greeting. The second argument is the target server.
    */
    public static void main(String[] args) throws Exception {
      String user = "world";
      String target = "localhost:"+args[0];
      
      ManagedChannel channel = Grpc.newChannelBuilder(target, InsecureChannelCredentials.create()).build();
      try {
        HelloWorldClient client = new HelloWorldClient(channel);
        client.greet(user);
      } finally {
        channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
      }
    }
  }