3 # Copyright (c) Twisted Matrix Laboratories.
4 # See LICENSE for details.
7 from twisted.internet.protocol import ClientFactory
8 from twisted.protocols.basic import LineReceiver
9 from twisted.internet import reactor
12 class EchoClient(LineReceiver):
14 def connectionMade(self):
15 self.sendLine("Hello, world!")
16 self.sendLine("What a fine day it is.")
17 self.sendLine(self.end)
19 def lineReceived(self, line):
20 print "receive:", line
22 self.transport.loseConnection()
24 class EchoClientFactory(ClientFactory):
27 def clientConnectionFailed(self, connector, reason):
28 print 'connection failed:', reason.getErrorMessage()
31 def clientConnectionLost(self, connector, reason):
32 print 'connection lost:', reason.getErrorMessage()
36 factory = EchoClientFactory()
37 reactor.connectTCP('localhost', 8000, factory)
40 if __name__ == '__main__':