CentOS thrift python demo
编辑接口文件 hellowworld.thrift
service HelloWorld {
string ping(),
string say(1:string msg)
}
编辑 server.py
#!/usr/bin/env python import socket
import sys
sys.path.append('./gen-py') from helloworld import HelloWorld
from helloworld.ttypes import * from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer class HelloWorldHandler:
def ping(self):
return "pong" def say(self, msg):
ret = "Received: " + msg
print ret
return ret handler = HelloWorldHandler()
processor = HelloWorld.Processor(handler)
transport = TSocket.TServerSocket("localhost", 9090)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) print "Starting thrift server in python..."
server.serve()
print "done!"
编辑
client.py
#!/usr/bin/env python import sys
sys.path.append('./gen-py') from helloworld import HelloWorld from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol try:
transport = TSocket.TSocket('localhost', 9090)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = HelloWorld.Client(protocol)
transport.open() print "client - ping"
print "server - " + client.ping() print "client - say"
msg = client.say("Hello!")
print "server - " + msg transport.close() except Thrift.TException, ex:
print "%s" % (ex.message)
运行:
thrift --gen py helloworld.thrift
python server.py
python client.py #这个分一个窗口运行
如果修改里面的一个方法或者增加一个调用方法的话,需要在 helloword.thrift 里面定义函数及参数。
在服务端运行代码 thrift -r --gen py helloworld.thrift
重新生成 gen-py 文件夹,将里面的代码拷贝到客户端的服务器。
CentOS thrift python demo的更多相关文章
- Linux CentOS下Python+robot framework环境搭建
Linux CentOS下Python+robot framework环境搭建 by:授客 QQ:1033553122 操作系统环境:CentOS 6.5-x86_64 下载地址:http://w ...
- Centos搭建Python+Nginx+Tornado+Mysql环境[转载]
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入 ...
- centos 更新python
1.CentOS安装Python的依赖包 yum groupinstall "Development tools"yum install zlib-devel bzip2-deve ...
- 转: CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法
from: http://www.linuxde.net/2014/05/15576.html CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法 2014/05/ ...
- CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法
CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法如下: 截至包子写本文的时候,pip最新为 1.5.5 wget --no-check-certificate h ...
- 在阿里云服务器上配置CentOS+Nginx+Python+Flask环境
在阿里云服务器上配置CentOS+Nginx+Python+Flask环境 项目运行环境 阿里云(单核CPU, 1G内存, Ubuntu 14.04 x64 带宽1Mbps), 具体购买和ssh连接阿 ...
- Linux CentOS下Python+robot framework环境搭建
转载自:http://blog.sina.com.cn/s/blog_13cc013b50102vof1.html 操作系统环境:CentOS 6.5-x86_64 下载地址:http://www.c ...
- 【转】Centos升级Python 2.7.12并安装pip、ipython
Centos系统一般默认就安装有Python2.6.6版本,不少软件需要2.7以上的,通过包管理工具安装不了最新的版本,通过源码编译可以方便安装指定版本,只需要把下面版本的数字换成你想要的版本号. 1 ...
- liunx CentOS 升级Python版本
CentOS python版本是V2.6.6,升级3.4.3. 1.下载 安装包:wget http://www.python.org/ftp/python/3.4.3/Python-3.4.3.tg ...
随机推荐
- Oracle基础 游标
一.游标 游标用来处理从数据库中检索的多行记录(使用SELECT语句).利用游标,程序可以逐个地处理和遍历一次检索返回的整个记录集. 为了处理SQL语句,Oracle将在内存中分配一个区域,这就是上下 ...
- mysql-DDL-创建数据库
创建一个数据库 • 建立数据库操作: 语法: create database 数据库名 叙述:创建一个具有指定名称的数据库.如果要创建的 数据库已经存在,或者没有创建它的适当权限,则此 语句失败. 例 ...
- React Native中常见操作
一.如何将项目安装到iOS手机上? 1.将手机于电脑连接好,并将Xcode打开连接上手机 2.在General -> Team 下添加自己的Apple ID. 3.改本地的IP地址: 4.点击 ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 3804 树链剖分
思路:将边权排序,然后插入线段树,这样就可以直接用二分查找确定答案. #pragma comment(linker, "/STACK:1024000000,1024000000") ...
- poj 3378 二维树状数组
思路:直接用long long 保存会WA.用下高精度加法就行了. #include<map> #include<set> #include<cmath> #inc ...
- 24 MUST HAVE ESSENTIAL LINUX APPLICATIONS IN 2016
Brief: Whare the must have applications for Linux? The answer is subjective and it depends on for wh ...
- IDG合伙人李丰:O2O中的C2C蕴藏巨大商机
[ 亿欧导读 ] IDG合伙人李丰表示,每个新趋势出现,都是在解决上一轮行业革新时没有解决好的市场需求.而O2O中的C2C将会出现巨大商机的原因在于移动互联网的出现创造了新的交互方式,可以更快速的匹配 ...
- struts2-获取WEB资源
1.什么是WE资源 2.为什么访问WEB资源 3.如何访问WEB资源 与Servlet API解耦的方式: 使用ActionContext: 实现XxxAware接口 以ApplicationAwar ...
- ASP.NET Ajax核心对象
本章学习目标 主要掌握AJAX的基本概念和实现机制,学习并创建XMLHttpRequest对象,使用XMLHttpRequestObject对象获取服务器端的数据 主要内容如下,请点击ASP.NET ...