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的方式实现前 ...
随机推荐
- Error: java.lang.UnsatisfiedLinkError: no ntvinv in java.library.path
Error Message When compiling or executing a Java application that uses the ArcObjects Java API, the ...
- JQuery思维导图
- c++重载运算符注意
c++重载运算符的时候加&或不加: 如果加了&表示引用,说明用的都是同一块内存.如果不加,那么用的就是一份拷贝,即不同的内存. 一般连续操作的时候要加&. 可以重新定义一个对象 ...
- 缓存插件 Spring支持EHCache缓存
Spring仅仅是提供了对缓存的支持,但它并没有任何的缓存功能的实现,spring使用的是第三方的缓存框架来实现缓存的功能.其中,spring对EHCache提供了很好的支持. 在介绍Spring的缓 ...
- JSP九个内置对象
JSP内置对象有: 1.request对象 客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应.它是HttpServletRequest类的实例. 2.r ...
- jquery indexOf使用方法
当无法确定在某个字符串中是否确实存在一个字符的时候,就可调用 indexOf() 和 lastIndexOf() 方法 indexOf() 和 lastIndexOf() 是js的用法,与jquery ...
- tarjan算法--求无向图的割点和桥
一.基本概念 1.桥:是存在于无向图中的这样的一条边,如果去掉这一条边,那么整张无向图会分为两部分,这样的一条边称为桥无向连通图中,如果删除某边后,图变成不连通,则称该边为桥. 2.割点:无向连通图中 ...
- 【poj1001】 Exponentiation
http://poj.org/problem?id=1001 (题目链接) 题意 求实数R的n次方,要求高精度. Solution SB题Wa了一下午,直接蒯题解. 高精度,小数点以及去前导后导零很麻 ...
- c++内存分配(new和delete)
c中malloc和free是函数,包含在stdlib.h头文件中,分配成功返回指针,失败返回空指针. 与new的区别是: 1,malloc与free是C++/C语言的标准库函数,new/delete是 ...
- php中静态变量和静态方法
1,静态变量:所有对象共享的变量成为静态变量.静态变量类似于全局变量,不过全局变量破坏对象的封装性,因此其对应于面向过程:静态变量对应于面向对象. 2,全局变量,全局变量的使用实例如下,声明全局变量时 ...