1
"""A process that reads from stdin and out using Twisted."""
4
# This makes sure that users don't have to set up their environment
5
# specially in order to run these programs from bin/.
7
pos = string.find(os.path.abspath(sys.argv[0]), os.sep+'Twisted')
9
sys.path.insert(0, os.path.abspath(sys.argv[0])[:pos+8])
10
sys.path.insert(0, os.curdir)
14
from twisted.python import log
15
from zope.interface import implements
16
from twisted.internet import interfaces
18
log.startLogging(sys.stderr)
20
from twisted.internet import protocol, reactor, stdio
23
class Echo(protocol.Protocol):
24
implements(interfaces.IHalfCloseableProtocol)
26
def connectionMade(self):
27
print "connection made"
29
def dataReceived(self, data):
30
self.transport.write(data)
32
def readConnectionLost(self):
33
print "readConnectionLost"
34
self.transport.loseConnection()
35
def writeConnectionLost(self):
36
print "writeConnectionLost"
38
def connectionLost(self, reason):
39
print "connectionLost", reason
42
stdio.StandardIO(Echo())