安装grpc模块
pip install grpcio
pip install grpc_tools
pip install protobuf
需要安装 protocol buffer editor
新建一个protocol buffer文件
建一个工程gr-pro,文件名为hello_p
rotobuffer
//使用哪种protobuff
syntax = 'proto3';
//包名
package test;
//写服务器里的服务,定义了一个服务框架,服务名叫pro,里面有个hellobw的函数,如何定义了请求helllobw和回复 helloreply
service pro{
rpc hellobw(hellobwreq) returns (hellobwreply){}
}
message hellobwreq{
string name = 1;
int32 age = 18;
}
message hellobwreply{
string result = 1;
}
在终端运行
>python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. hello_p
rotobuffer
hello_protobuffer即文件名