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的方式实现前 ...
随机推荐
- jquery.validate.js常用扩展函数
$(function () { // 判断整数value是否等于0 jQuery.validator.addMethod("isIntEqZero", function (valu ...
- Redis——分布式简单使用
Redis简介:Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. Redis安装:参考博客http://www ...
- SimpleDateFormat出错
今天写了一个SB代码,就是字符串“2014-04-03”转换为java.sql.Date.因为java.sql.Date extends java.util.Date.所以一般的思路是先将String ...
- z-index详解
来源于:http://www.cnblogs.com/ForEvErNoME/p/3373641.html 概念 z-index 属性设置元素的堆叠顺序.拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的 ...
- Lucene 4.7 --高亮显示
jar lucene-analyzers-common-4.7.0.jar lucene-analyzers-smartcn-4.7.0.jar lucene-core-4.7.0.jar lucen ...
- 未完结第八节 JBPM流程节点
1.12个节点介绍 2.Node节点
- JAVA的整型与字符串相互转换
1如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([S ...
- STL简单应用问题
问题: Input输入的第一行是一个整数T( 1 <= T <= 100 ),表示有几组输入数据.每组输入由4部分组成:(1)一个字典,最多包含2000个单词,每个单词一行.(2)一行字符 ...
- POJ1743 Musical Theme
Description A musical melody is represented as a sequence of N (1<=N<=20000)notes that are int ...
- Handler.dispatchMessage handleMessage
"main@3972" prio=5 runnable java.lang.Thread.State: RUNNABLE at com.ease.financialoa.modul ...