环境: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的更多相关文章

  1. Python Twisted、Reactor

    catalogue . Twisted理论基础 . 异步编程模式与Reactor . Twisted网络编程 . reactor进程管理编程 . Twisted并发连接 1. Twisted理论基础 ...

  2. 【转】Python Twisted介绍

    Python Twisted介绍 作者:Jessica McKellar 原文链接 Twisted是用Python实现的基于事件驱动的网络引擎框架.Twisted诞生于2000年初,在当时的网络游戏开 ...

  3. Python twisted article

    学习python twisted 的好文章 An Introduction to Asynchronous Programming and Twisted Reference: http://kron ...

  4. python twisted教程[资料]

    python twisted教程 一,异步编程 http://www.douban.com/note/232200511/   python twisted教程 二:缓慢的诗 http://www.d ...

  5. Python - twisted web 入门学习之一

    原文地址:http://zhouzhk.iteye.com/blog/765884 python的twisted框架中带了一个web server: twisted web.现在看看怎么用. 一)准备 ...

  6. python twisted启动定时服务

    以下是python脚本send_mms.py #############################################!/usr/bin/python# -*- coding: ut ...

  7. Python Twisted介绍

    原文链接:http://www.aosabook.org/en/twisted.html 作者:Jessica McKellar Twisted是用Python实现的基于事件驱动的网络引擎框架.Twi ...

  8. python Twisted安装报错

    系统 mac pro 错误信息: IOError: [Errno 63] File name too long: '/var/folders/72/byjy11cs0dj_z3rjtxnj_nn000 ...

  9. 用python.twisted.logfile每天记录日志,并用不记录stdout中的内容

    #导入的头 from twisted.python import logfrom twisted.python.logfile import * #开始记录,输入日志名和存放的路径,setStdout ...

  10. Python Twisted系列教程3:初步认识Twisted

    作者:dave@http://krondo.com/our-eye-beams-begin-to-twist/ 译者:杨晓伟(采用意译) 可以从这里从头开始阅读这个系列. 用twisted的方式实现前 ...

随机推荐

  1. HDU 5115 Dire Wolf 区间dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5115 Dire Wolf Time Limit: 5000/5000 MS (Java/Others ...

  2. Productivity Power Tools 动画演示--给力的插件工具

    免费的精品: Productivity Power Tools 动画演示 Productivity Power Tools 是微软官方推出的 Visual Studio 扩展,被用以提高开发人员生产率 ...

  3. 列表 list

    例子: #!/usr/bin/python li = list([11,22,33,66,99,77]) print(li) li.extend((44,55,)) print(li) ret = l ...

  4. Oracle创建DBLink的方法

    文章从http://blog.csdn.net/davidhsing/article/details/6408770拷贝过来的 1.如果需要创建全局 DBLink,则需要先确定用户有创建 dblink ...

  5. UVa 1347 Tour

    Tour Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Description   Joh ...

  6. ubuntu 12.04安装telnet和ssh服务

    ubuntu安装telnet服务 1. sudo apt-get install xinetd telnetd sudo vi /etc/inetd.conf并加入以下一行,假如没有发现这个文件,自己 ...

  7. view视图文件中的input等输入框必须含有name属性,不然控制器里的动作formCollection是没有值的

    view视图文件中的input等输入框必须含有name属性,不然控制器里的动作formCollection是没有值的,就是没有name属性,后台获取不到值

  8. jquery------导入jquery UI要使用的文件

    JQuery版本下载地址:http://jquery.com/download/ JQuer UI两个主要下载地址:http://jqueryui.com/download/  只需要里面的jquer ...

  9. ThinkPHP 购物商城网站(数据库中增删改查的功能实现)——————重点——————

    控制器 ---------------------GoodsController.class.php------------------------------------------------- ...

  10. chrome 阻止跨域操作的解决方法 --disable-web-security

    做chrome插件时,遇到https页面上请求htttp页面资源时被blocked的问题,初苦寻解决方法未果,最后找到: 给chrome加上 --disable-web-security 参数