python-twisted
环境:win7 64位,python 2.7.3
安装:
http://twistedmatrix.com/Releases/Twisted/14.0/Twisted-14.0.0.win-amd64-py2.7.exe
https://pypi.python.org/packages/2.7/z/zope.interface/zope.interface-4.1.1.win-amd64-py2.7.exe#md5=c3e22b49f84adaf169ec0d52eded4c8d
视需要安装:http://softlayer-sng.dl.sourceforge.net/project/wxpython/wxPython/3.0.0.0/wxPython3.0-win64-3.0.0.0-py27.exe
helloworld:
simpleserv.py(服务器端):
from twisted.internet import reactor, protocol class Echo(protocol.Protocol):
"""This is just about the simplest possible protocol""" def dataReceived(self, data):
"As soon as any data is received, write it back."
self.transport.write(data) def main():
"""This runs the protocol on port 8000"""
factory = protocol.ServerFactory()
factory.protocol = Echo
reactor.listenTCP(8000,factory)
reactor.run() # this only runs if the module was *not* imported
if __name__ == '__main__':
main()
simpleclient.py(客户端)
from twisted.internet import reactor, protocol # a client protocol class EchoClient(protocol.Protocol):
"""Once connected, send a message, then print the result.""" def connectionMade(self):
self.transport.write("hello, world!") def dataReceived(self, data):
"As soon as any data is received, write it back."
print "Server said:", data
data2= raw_input()
if data2!='EOM':
self.transport.write(data2)
else:
self.transport.loseConnection() def connectionLost(self, reason):
print "connection lost" class EchoFactory(protocol.ClientFactory):
protocol = EchoClient def clientConnectionFailed(self, connector, reason):
print "Connection failed - goodbye!"
reactor.stop() def clientConnectionLost(self, connector, reason):
print "Connection lost - goodbye!"
reactor.stop() # this connects the protocol to a server runing on port 8000
def main():
f = EchoFactory()
reactor.connectTCP("localhost", 8000, f)
reactor.run() # this only runs if the module was *not* imported
if __name__ == '__main__':
main()
测试:
1.开启服务器端
2.开启客户端:
更多文档参考这里。
python-twisted的更多相关文章
- Python Twisted、Reactor
catalogue . Twisted理论基础 . 异步编程模式与Reactor . Twisted网络编程 . reactor进程管理编程 . Twisted并发连接 1. Twisted理论基础 ...
- 【转】Python Twisted介绍
Python Twisted介绍 作者:Jessica McKellar 原文链接 Twisted是用Python实现的基于事件驱动的网络引擎框架.Twisted诞生于2000年初,在当时的网络游戏开 ...
- Python twisted article
学习python twisted 的好文章 An Introduction to Asynchronous Programming and Twisted Reference: http://kron ...
- python twisted教程[资料]
python twisted教程 一,异步编程 http://www.douban.com/note/232200511/ python twisted教程 二:缓慢的诗 http://www.d ...
- Python - twisted web 入门学习之一
原文地址:http://zhouzhk.iteye.com/blog/765884 python的twisted框架中带了一个web server: twisted web.现在看看怎么用. 一)准备 ...
- python twisted启动定时服务
以下是python脚本send_mms.py #############################################!/usr/bin/python# -*- coding: ut ...
- Python Twisted介绍
原文链接:http://www.aosabook.org/en/twisted.html 作者:Jessica McKellar Twisted是用Python实现的基于事件驱动的网络引擎框架.Twi ...
- python Twisted安装报错
系统 mac pro 错误信息: IOError: [Errno 63] File name too long: '/var/folders/72/byjy11cs0dj_z3rjtxnj_nn000 ...
- 用python.twisted.logfile每天记录日志,并用不记录stdout中的内容
#导入的头 from twisted.python import logfrom twisted.python.logfile import * #开始记录,输入日志名和存放的路径,setStdout ...
- Python Twisted系列教程3:初步认识Twisted
作者:dave@http://krondo.com/our-eye-beams-begin-to-twist/ 译者:杨晓伟(采用意译) 可以从这里从头开始阅读这个系列. 用twisted的方式实现前 ...
随机推荐
- 第四章:javascript: 栈
列表是一种最自然的数据组织方式.上一章已经介绍如何使用List类将数据组织成一个列表.如果数据存储的顺序不重要.也不必对数据进行查找,那么列表就是一种再好不过的数据结构.对于其它的一些应用,列表就显得 ...
- Tensorflow学习笔记(一):MNIST机器学习入门
学习深度学习,首先从深度学习的入门MNIST入手.通过这个例子,了解Tensorflow的工作流程和机器学习的基本概念. 一 MNIST数据集 MNIST是入门级的计算机视觉数据集,包含了各种手写数 ...
- (练习)rational rose进行用例图设计
用例图:
- Java泛型中E、T、K、V等的含义
Java泛型中的标记符含义: E - Element (在集合中使用,因为集合中存放的是元素) T - Type(Java 类) K - Key(键) V - Value(值) N - Numbe ...
- note.js之 Nodejs+Express4在windows下的配置
本篇主要介绍一下在windows平台下采用nodejs+express4框架+Mongodb实现网站的开发.其实本人是不赞同在Windows平台下使用node.js进行开发,但由于公司后台工程师都是采 ...
- SpringMVC实战
一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 1 2 3 4 5 6 ...
- bzoj 1193 贪心
如果两点的曼哈顿距离在一定范围内时我们直接暴力搜索就可以得到答案,那么开始贪心的跳,判断两点横纵坐标的差值,差值大的方向条2,小的条1,不断做,直到曼哈顿距离较小时可以暴力求解. 备注:开始想的是确定 ...
- 【长期更新】--神犇的BLOGS(各种高端讲解)
KMP字符串匹配算法: http://kb.cnblogs.com/page/176818/ http://blog.csdn.net/yutianzuijin/article/details/119 ...
- BZOJ1432 [ZJOI2009]Function
Description Input 一行两个整数n; k. Output 一行一个整数,表示n 个函数第k 层最少能由多少段组成. Sample Input 1 1 Sample Output 1 H ...
- MVC传值汇总
方法一: Url传参是通过Get的方式,一般我们都是通过一定规则的Url来传参.比如下面的URL. http://localhost/contorller/action/?Params1=a& ...