Giter VIP home page Giter VIP logo

grpc-examples's Introduction

gRPC Examples

Introduction

gRPC C++ examples built with CMake.

Dependencies

  • gRPC 1.34
  • CMake 3.13.0+

Files

.
├── CMakeLists.txt
├── docker
│   └── grpc.Dockerfile
├── grpc
│   ├── arithmetics
│   │   ├── arithmetics_client.cc
│   │   ├── arithmetics_server.cc
│   │   └── CMakeLists.txt
│   ├── CMakeLists.txt
│   └── greetings
│       ├── CMakeLists.txt
│       ├── greetings_client.cc
│       └── greetings_server.cc
├── LICENSE.md
├── protos
│   ├── arithmetics.proto
│   └── greetings.proto
└── README.md

Usages

Build Docker Image

$ docker build -f docker/grpc.Dockerfile --build-arg GPRC_VERSION=1.34.0 --build-arg NUM_JOBS=8 --tag grpc-cmake:1.34.0 .

To build for different gRPC versions and use different number of CPU threads, please change the values in the build arguments.

Run Docker Container

Two separate Docker containers should be started for the gRPC server and the gRPC client.

$ docker run -it --rm --network host -v $(pwd):/mnt grpc-cmake:1.34.0

Build Examples

$ cmake -B build
$ cmake --build build --config Release --parallel

All the executable files would be generated in build/grpc directory.

Run Examples

Arithmetics

In one terminal, we start the gRPC server.

$ ./build/grpc/arithmetics/arithmetics_server
Server listening on 0.0.0.0:50051

In another terminal, we start the gRPC client.

$ ./build/grpc/arithmetics/arithmetics_client 
Please enter your binary arithmetic expression:
300 + 200
gRPC returned: 
500
Please enter your binary arithmetic expression:
300 - 200
gRPC returned: 
100
Please enter your binary arithmetic expression:
300 * 200
gRPC returned: 
60000
Please enter your binary arithmetic expression:
300 / 200
gRPC returned: 
1
Please enter your binary arithmetic expression:

Hello World

In one terminal, we start the gRPC server.

$ ./build/grpc/greetings/greetings_server 
Server listening on 0.0.0.0:50051

In another terminal, we start the gRPC client.

$ ./build/grpc/greetings/greetings_client 
Please enter your user name:
Lei Mao
gRPC returned: 
Hello Lei Mao!
Please enter your user name:
Michael Jordan
gRPC returned: 
Hello Michael Jordan!
Please enter your user name:
Kobe Bryant
gRPC returned: 
Hello Kobe Bryant!
Please enter your user name:

References

grpc-examples's People

Contributors

leimao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.