Here we build and test two gRPC servers, one in golang and another in Python.
The servers implements just one function, Test1.
A proto file define Request and Response message from Test1 function:
syntax = "proto3";
option go_package = ".;service1";
service MyRPC1 {
// just one function inside RPC server
rpc Test1(Benchmark) returns(Response){}
}
message Response {
string text = 1; // server response
uint32 crc32 = 2; // computed crc32 of received buffer
}
message Benchmark {
string name = 1; // benchmark name
bytes buffer = 2; // benchmark buffer
}
The protoc compiler generate "stub files" used to build the code.
The code import the "stub files", then the server implement Test1 function and the client call the Test1 function.
There are batch files (for Windows) used to generate "stub files" and to call the servers and clients, but the recipe also works in Linux with some minor changes.
The servers can use an OpenSSL certificate, but the user authentification is not implemented.
The servers compute crc32 of received buffer and return it to client, the clients also compute crc32 of buffer and verify it.
The Python implementation works on both Python 2.7 and Python 3.8
SET HOST=localhost:6002
cd go-server
start "go gRPC server secure on %HOST%" go run . -host %HOST% -secured
SET HOST=localhost:6002
SET BS=2048
SET N=5
title Test go server secured - %HOST%
cd go-client
go run . -host %HOST% -bs %BS% -n %N% -secured
cd ..\py-client-server
python client.py -host %HOST% -bs %BS% -n %N% -secured
pause
SET HOST=localhost:6004
start "py gRPC server secure on %HOST%" python server.py -host %HOST% -secured
SET HOST=localhost:6004
SET BS=2048
SET N=5
title Test py server secured - %HOST%
cd go-client
go run . -host %HOST% -bs %BS% -n %N% -secured
cd ..\py-client-server
python client.py -host %HOST% -bs %BS% -n %N% -secured
pause