twisted: echo server

from twisted.internet import protocol, reactor

class Echo(protocol.Protocol):
    def dataReceived(self, data):
        self.transport.write(data)

class EchoFactory(protocol.Factory):
    def buildProtocol(self, addr):
        return Echo()

reactor.listenTCP(1234, EchoFactory())
reactor.run()

 

run server:

python testTwisted.py

 

run client:

telnet localhost 1234

posted on 2012-01-13 00:51  cutepig  阅读(339)  评论(0编辑  收藏  举报

导航