A simple echo client & server based on twisted framework
2013-07-31 15:59
651 查看
echoserver.py
echoclient.py
from twisted.internet.protocol import Protocol, ServerFactory from twisted.internet import reactor __author__ = 'xueleng' class Echo(Protocol): def dataReceived(self, data): self.transport.write(data) class EchoFactory(ServerFactory): def buildProtocol(self, addr): return Echo(); reactor.listenTCP(8000, EchoFactory()) reactor.run()
echoclient.py
from twisted.internet.protocol import Protocol, ClientFactory from twisted.internet import reactor __author__ = 'xueleng' class EchoClient(Protocol): def connectionMade(self): self.transport.write('Hello, World!') def dataReceived(self, data): print 'Server said: %s' % data self.transport.loseConnection() class EchoFactory(ClientFactory): def buildProtocol(self, addr): return EchoClient() def clientConnectionFailed(self, connector, reason): print 'Connection failed' reactor.stop() def clientConnectionLost(self, connector, reason): print 'Connection lose' reactor.stop() reactor.connectTCP('localhost', 8000, EchoFactory()) reactor.run()
相关文章推荐
- Simple TCP/IP Echo Server & Client Application in C#
- 回射客户端服务器select 修改版[2]( echo client && server improved by select function)
- libevent (1) 入门教程:Echo Server based on libevent
- Eli Bendersky's website » Code sample – socket client based on Twisted with PyQt
- python webserver, based on SimpleHTTPServer
- 回射客户端服务器epoll( echo client && server improved by epoll function )
- 回射客户端服务器UDP(echo client&&server based on UDP)
- Libevent:Echo Server Based on libevent
- libevent入门教程:Echo Server based on libevent
- Node.js: What is the best "full stack web framework" (with scaffolding, MVC, ORM, etc.) based on Node.js / server-side JavaScript? - Quora
- [转载]libevent入门教程:Echo Server based on libevent
- Simple HTTP Proxy Server Implementation, based on wcol - Projects - Michael Vorburger's Private Homepage
- libevent 入门教程:Echo Server based on libevent(转)
- libevent入门教程:Echo Server based on libevent
- libevent 入门教程:Echo Server based on libevent(转)
- libevent入门教程:Echo Server based on libevent
- libevent入门教程:Echo Server based on libevent
- 回射客户端服务器中僵尸进程的处理( the solution of zombie process in the echo client && server )
- libevent入门教程:Echo Server based on libevent
- libevent入门教程:Echo server based on libevent