2 # Copyright (c) Twisted Matrix Laboratories.
3 # See LICENSE for details.
7 An example client. Run simpleserv.py first before running this.
10 from twisted.internet import reactor, protocol
15 class EchoClient(protocol.Protocol):
16 """Once connected, send a message, then print the result."""
18 def connectionMade(self):
19 self.transport.write("hello, world!")
21 def dataReceived(self, data):
22 "As soon as any data is received, write it back."
23 print "Server said:", data
24 self.transport.loseConnection()
26 def connectionLost(self, reason):
27 print "connection lost"
29 class EchoFactory(protocol.ClientFactory):
32 def clientConnectionFailed(self, connector, reason):
33 print "Connection failed - goodbye!"
36 def clientConnectionLost(self, connector, reason):
37 print "Connection lost - goodbye!"
41 # this connects the protocol to a server runing on port 8000
44 reactor.connectTCP("localhost", 8000, f)
47 # this only runs if the module was *not* imported
48 if __name__ == '__main__':