OLD | NEW |
| (Empty) |
1 """A process that reads from stdin and out using Twisted.""" | |
2 | |
3 ### Twisted Preamble | |
4 # This makes sure that users don't have to set up their environment | |
5 # specially in order to run these programs from bin/. | |
6 import sys, os, string | |
7 pos = string.find(os.path.abspath(sys.argv[0]), os.sep+'Twisted') | |
8 if pos != -1: | |
9 sys.path.insert(0, os.path.abspath(sys.argv[0])[:pos+8]) | |
10 sys.path.insert(0, os.curdir) | |
11 ### end of preamble | |
12 | |
13 | |
14 from twisted.python import log | |
15 from zope.interface import implements | |
16 from twisted.internet import interfaces | |
17 | |
18 log.startLogging(sys.stderr) | |
19 | |
20 from twisted.internet import protocol, reactor, stdio | |
21 | |
22 | |
23 class Echo(protocol.Protocol): | |
24 implements(interfaces.IHalfCloseableProtocol) | |
25 | |
26 def connectionMade(self): | |
27 print "connection made" | |
28 | |
29 def dataReceived(self, data): | |
30 self.transport.write(data) | |
31 | |
32 def readConnectionLost(self): | |
33 print "readConnectionLost" | |
34 self.transport.loseConnection() | |
35 def writeConnectionLost(self): | |
36 print "writeConnectionLost" | |
37 | |
38 def connectionLost(self, reason): | |
39 print "connectionLost", reason | |
40 reactor.stop() | |
41 | |
42 stdio.StandardIO(Echo()) | |
43 reactor.run() | |
OLD | NEW |