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

Powered by Jekyll and Theme by solid

本站总访问量