thrift编写服务端 客户端
雷顿大数据技术学院:http://www.leidun.site/
1 编写 thrift文件
文件名
helloworld.thrift
HelloWorld{ping()say(:msg)}
使用命令 thrift --gen py hellowrold.thrift生成基础文件
生成结果目录格式如下
server.py
syssys.path.insert()sys.pathhelloworldHelloWorldhelloworld.ttypes*thrift.transportTSocketthrift.transportTTransportthrift.protocolTBinaryProtocolthrift.serverTServerHelloWorldHandler:():(msg):ret=+msgretrethandler=HelloWorldHandler()processor=HelloWorld.Processor(handler)transport=TSocket.TServerSocket()tfactory=TTransport.TBufferedTransportFactory()pfactory=TBinaryProtocol.TBinaryProtocolFactory()server=TServer.TSimpleServer(processortransporttfactorypfactory)server.serve()
client.py
syssys.path.insert()helloworldHelloWorldthriftThriftthrift.transportTSocketthrift.transportTTransportthrift.protocolTBinaryProtocol:transport=TSocket.TSocket()transport=TTransport.TBufferedTransport(transport)protocol=TBinaryProtocol.TBinaryProtocol(transport)client=HelloWorld.Client(protocol)transport.open()msg=client.say()+msgtransport.close()Thrift.TExceptionex:%(ex.message)
启动server clien
python server.py
python client.py
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。