from twisted.internet import epollreactor
epollreactor.install()
from twisted.internet import reactor
from twisted.internet.protocol import Protocol,Factory
from twisted.protocols.basic import LineReceiver
class EchoServer(Protocol):
def connectionMade(self):
print 'Get connection from',self.transport.client
def lineReceived(self,line):
self.transport.write(line)
factory = Factory()
factory.protocol = EchoServer
port = 1234
reactor.listenTCP(port,factory)
reactor.run()
本文介绍如何使用 Twisted 框架在 Python 中实现一个简单的 TCP 回显服务器。通过安装 epollreactor 并利用 Protocol 和 Factory 类创建了一个能够接收客户端连接并返回接收到的数据的服务端程序。
5万+

被折叠的 条评论
为什么被折叠?



