...
1
18
19
20 package main
21
22 import (
23 "context"
24 "flag"
25 "time"
26
27 "google.golang.org/grpc"
28 "google.golang.org/grpc/credentials/alts"
29 "google.golang.org/grpc/grpclog"
30
31 testgrpc "google.golang.org/grpc/interop/grpc_testing"
32 testpb "google.golang.org/grpc/interop/grpc_testing"
33 )
34
35 var (
36 hsAddr = flag.String("alts_handshaker_service_address", "", "ALTS handshaker gRPC service address")
37 serverAddr = flag.String("server_address", ":8080", "The port on which the server is listening")
38
39 logger = grpclog.Component("interop")
40 )
41
42 func main() {
43 flag.Parse()
44
45 opts := alts.DefaultClientOptions()
46 if *hsAddr != "" {
47 opts.HandshakerServiceAddress = *hsAddr
48 }
49 altsTC := alts.NewClientCreds(opts)
50
51 conn, err := grpc.Dial(*serverAddr, grpc.WithTransportCredentials(altsTC), grpc.WithBlock())
52 if err != nil {
53 logger.Fatalf("gRPC Client: failed to dial the server at %v: %v", *serverAddr, err)
54 }
55 defer conn.Close()
56 grpcClient := testgrpc.NewTestServiceClient(conn)
57
58
59 ctx := context.Background()
60 request := &testpb.Empty{}
61 if _, err := grpcClient.EmptyCall(ctx, request); err != nil {
62 logger.Fatalf("grpc Client: EmptyCall(_, %v) failed: %v", request, err)
63 }
64 logger.Info("grpc Client: empty call succeeded")
65
66
67
68 time.Sleep(1 * time.Second)
69 }
70
View as plain text