Skip to content

takassh/simple-grpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What's this

  • for studying grpc
  • implement server side by golang
  • implement client side by golang and flutter

reference

feature

how to implement

  1. create .proto file like simple_grpc.proto
  2. run
    protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    simplegrpc/simple_grpc.proto
  3. server implements SimpleGrpcServer interface and client implements SimpleGrpcClient interface. These files are in simplegrpc/simple_grpc_grpc.pb.go
  4. start the server
    grpcServer := grpc.NewServer(opts...)
    pb.RegisterSimpleGrpcServer(grpcServer, newServer())
    grpcServer.Serve(lis)
  5. create the channel on client
    var opts []grpc.DialOption
    conn, err := grpc.Dial(*serverAddr, opts...)
    if err != nil {
    ...
    }
    defer conn.Close()
    client := pb.NewRouteGuideClient(conn)
  6. client can call our service methods via client val

how to run

  • run the server go run server/server.go
  • run the client go run client/client.go
you will see following outputs
Getting feature for point (409146138, -746188906)
name:"Berkshire Valley Management Area Trail, Jefferson, NJ, USA" location:<latitude:409146138 longitude:-746188906 >
Getting feature for point (0, 0)
location:<>
Looking for features within lo:<latitude:400000000 longitude:-750000000 > hi:<latitude:420000000 longitude:-730000000 >
name:"Patriots Path, Mendham, NJ 07945, USA" location:<latitude:407838351 longitude:-746143763 >
...
name:"3 Hasta Way, Newton, NJ 07860, USA" location:<latitude:410248224 longitude:-747127767 >
Traversing 56 points.
Route summary: point_count:56 distance:497013163
Got message First message at point(0, 1)
Got message Second message at point(0, 2)
Got message Third message at point(0, 3)
Got message First message at point(0, 1)
Got message Fourth message at point(0, 1)
Got message Second message at point(0, 2)
Got message Fifth message at point(0, 2)
Got message Third message at point(0, 3)
Got message Sixth message at point(0, 3)

For Flutter Client (only native)

how to set up for Flutter (only native)

  • reference
  • install grpc package
  • install protoc-gen-dart
    dart pub global activate protoc_plugin
    
  • generate client stub
    protoc --dart_out=grpc:client/flutter_client/lib/generated -Isimplegrpc simplegrpc/simple_grpc.proto

how to test

  1. run golang server go run server/server.go
  2. run flutter app
  3. tap button

For React Client (TODO)

how to set up for React

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published