C++ client - C# server implementation over grpc connection with async unary and Bidiractional stream messages
This solution is include async Unary & Bidirectional messages implematation for C++ client & C# server. During my research, I found the grpc documentation is lacking. Therefore, I'm releasing my working version.
✨ ✨
- C++ client
- C# server
- Unary messages
- Async Unary Messages (using completion queue)
- Bidirectional Stream Messages.
- Website - Official documentation, libraries, resources, samples and FAQ
- Technical documentation - Collection of useful technical documentation
- gRPC status codes - Status codes and their use in gRPC
- gRPC status code mapping - HTTP to gRPC Status Code Mapping
- grpc-errors - Code examples in each language on how to return and handle error statuses.
- API Design Guide - Google Cloud API Design Guide useful for gRPC API design insights
- Community links - Mailing list, Gitter, Twitter, Reddit
First, install vcpkg package manager on your system using the official instructions: in powerShell:
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
Depanding on your OS:
- Bootstrap on Linux:
./bootstrap-vcpkg.sh
- Bootstrap on Windows instead:
./bootstrap-vcpkg.bat
Next, install gRPC using vcpkg package manager:
./vcpkg install grpc
for user wide integration use:
vcpkg integrate install
for specific project integration use:
vcpkg integrate project
follow instructions output in Powershell With a project open, go to Tools->NuGet Package Manager->Package Manager Console and paste: Install-Package ****** -Source "****\vcpkg\scripts\buildsystems" (replace ** with powershell output)
After grpc installed -> update googlePath macro to vcpckg installation location + "installed\x64-windows\include" (choose your relavant os folder)
In order to use grpc communication(Google's Protocol Buffers) we need to define a service, specifying the methods that can be called remotely with their parameters and return types.
we do this inside our .proto files. To learn more about protocol buffers see the protocol buffers documentation
gRPC uses protoc with a special gRPC plugin to generate code from your proto file.
use these commands to generate c++ code:
$(protobufPath)protoc -I=$(protosPath) -I $(googlePath) --cpp_out=$(ProjectDir)Generated $(protosPath)*.proto
$(protobufPath)protoc -I $(protosPath) -I $(googlePath) --grpc_out=$(ProjectDir)Generated --plugin=protoc-gen-grpc=$(grpcPath)grpc_cpp_plugin.exe $(protosPath)*.proto
where :
- protobufPath -> protoc.exe location inside installed grpc
- protosPath -> location of *.proto files to generate from.
- googlePath -> vcpckg installation location + "installed\x64-windows\include"
- --cpp_out/--grpc_out -> output location
- grpcPath -> googlePath + \grpc\x64-windows\tools\grpc\
Insert the above lines as a preBuild event to always keep your source code up to date.
MIT