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 ...
随机推荐
- MySQL关于InnoDB的几个错误
阿里云服务器上装有MySQL 5.6,这几天MySQL服务经常死掉,启动MySQL服务(service mysql start),却报如下错误 Starting MySQL.. ERROR! The ...
- 使用SFTP上传文件到服务器的简单使用
最近用到SFTP上传文件查找了一些资料后自己做了一点总结,方便以后的查询 /** * 将文件上传到服务器 * * @param filePath * 文件路径 * @param channelSftp ...
- SQL Server 2008数据类型
在创建表时,必须为表中的每列指派一种数据类型. 今天在研究二进制存储图片时候竟然不知道image类型就是二进制类型?!所有就搜集了sql中的各种数据类型汇总,成功在于点滴积累. 1. 字符数据类型 数 ...
- 瀑布流插件(jquery.masonry.js)
什么是瀑布流?去看看Pinterest(这才是鼻祖),Mark之,蘑菇街,点点网,还有腾讯的微博广场吧.随着页面滚动条向下滚动,还会不断加载数据块并附加至当前尾部. Masonry是一款很好用的jqu ...
- iOS-画板的实现
先上一张效果图,有看下去的动力 再来一张工程图片 好,首先是对线的实体的封装,在LineEntity.h文件中创建一个点的数组 然后在LineEntity.m文件中,在初始化方法中给points变量开 ...
- 20141017--异常语句try-catch
//try-catch 尝试(try)-抓获(catch) try//尝试,保护起来,使程序出错也能执行 { //确定不会出错时不要用try,当不确定时使用try-catch可以捕获错误, int i ...
- (转)mongoDB 禁用大内存页面 transparent_hugepage=never
最近在学mongoDB,安装倒没什么困难,有yum仓库.不过接入ctl后的一条warning倒挺让人烦心的. 1 2 2015-03-22T09:27:00.222+0800 I CONTROL [ ...
- Integer类型值相等或不等分析
看到博客园一位博友写的面试问题,其中一题是 Integer a = 1; Integer b = 1 ; (a == b)?true :false; 当时我一看,这不是明显的true 嘛, 看到评论 ...
- ubuntu 常用参数设置
在Linux下,对于参数的设置,一般来说,都遵循这个规律.每一个功能程序,一定对于一个对于名字的配置文件. 涉及到多用户的功能配置,一定有一个全局的配置文件,对所有用户都生效,而每个用 ...
- 理解ClassLoader基本原理
当JVM(Java虚拟机)启动时,会形成由三个类加载器组成的初始类加载器层次结构: bootstrap classloader | exte ...