twisted udp 实现示例,twistedudp,from twisted
twisted udp 实现示例,twistedudp,from twisted
from twisted.internet.protocol import DatagramProtocolfrom twisted.internet import reactorimport osclass MulticastPingPong(DatagramProtocol): def startProtocol(self): self.transport.setTTL(5) self.transport.joinGroup("228.0.0.5") def datagramReceived(self, datagram, address): print "%s"%repr(datagram)def talk(): import socket pid = os.getpid() while True: data = raw_input() sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) sock.sendto("%s say:%s"%(pid, data), ("228.0.0.5", 8005))reactor.listenMulticast(8005, MulticastPingPong(), listenMultiple=True)reactor.callInThread(talk)reactor.run()
Twisted Matrix 是一种越来越受欢迎的纯 Python 框架,用来进行网络服务和应用程序的编程。虽然 Twisted Matrix 中有大量松散耦合的模块化组件,但该框架的中心概念还是非阻塞异步服务器这一思想。在本文中,David 向您介绍了一种新编程风格,对于习惯于线程技术或分叉服务器的开发人员来说,这是一种新颖的编程风格,但它却能在繁重负载的情况下带来极高的效率。
相关内容
- webpy更新程序时删除pyc文件的shell脚本,webpypyc,pyc文件是
- Python连接SqlServer代码示例,pythonsqlserver,Python编程语言简
- python 解析xml示例代码,pythonxml示例代码,python有三种方
- 理解python的decorator,pythondecorator,假定有这么一个需求,
- python调用外部命令获得执行结果,python外部命令,要在
- python正则表达式re模块使用总结,python正则表达式,一、
- Pythonic的Redis库 OOREDIS 介绍,pythonicredis,用Redis的朋友们
- python使用pgsql连接postgresql,pgsqlpostgresql,决定使用pytho
- python读写excel例子,python读写excel,你知道吗?python也
- python中清除html标签,pythonhtml标签,如下代码实现清除
评论关闭