首先需要thrift编译器,thrift-0.12.0.exe,APache官网可以下载,不过网络不好的话可以用百度云的文件:
链接:https://pan.baidu.com/s/1uF32l-zqP6VWFGy0zuGRhA
提取码:xba4
接下来,自己写个简单的thrift协议,保存为hello.thrift文件如下
/*
thrift接口定义文件
say接口接收一个参数msg,返回数值类型
body接口接收3个参数,返回字符串类型
*/
service HelloService {
i32 say(
1:string msg);
string body(
1:i32 id
2:string name
3:i32 age)
}
然后使用thrift分别生成Python代码:在cmd输入如下命令
thrift-0.12.0.exe --gen py hello.thrift
则会生成如下文件夹gen-py:
进入gen-py目录:
新建服务端Python代码, service.py:
# coding: utf-8
from hello imp