github.com/noirx94/tendermintmp@v0.0.1/rpc/grpc/client_server.go (about) 1 package coregrpc 2 3 import ( 4 "net" 5 6 "golang.org/x/net/context" 7 "google.golang.org/grpc" 8 9 tmnet "github.com/tendermint/tendermint/libs/net" 10 ) 11 12 // Config is an gRPC server configuration. 13 type Config struct { 14 MaxOpenConnections int 15 } 16 17 // StartGRPCServer starts a new gRPC BroadcastAPIServer using the given 18 // net.Listener. 19 // NOTE: This function blocks - you may want to call it in a go-routine. 20 func StartGRPCServer(ln net.Listener) error { 21 grpcServer := grpc.NewServer() 22 RegisterBroadcastAPIServer(grpcServer, &broadcastAPI{}) 23 return grpcServer.Serve(ln) 24 } 25 26 // StartGRPCClient dials the gRPC server using protoAddr and returns a new 27 // BroadcastAPIClient. 28 func StartGRPCClient(protoAddr string) BroadcastAPIClient { 29 conn, err := grpc.Dial(protoAddr, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc)) 30 if err != nil { 31 panic(err) 32 } 33 return NewBroadcastAPIClient(conn) 34 } 35 36 func dialerFunc(ctx context.Context, addr string) (net.Conn, error) { 37 return tmnet.Connect(addr) 38 }