Hi all,<br> I'm learning Twisted by reading Abe Fettig's "Twisted Networking Programming Essentials". I tried the example 2-6 (dataforward.py) but the program hung after printing 'Connected to ...'. I don't know Twisted enough to figure out where the problem is. Will anybody tell me why? I paste the code here:
<br><br>--------------------------------------------------------------<br>from twisted.internet import stdio, reactor, protocol<br>from twisted.protocols import basic<br>import re<br><br>class DataForwardingProtocol(protocol.Protocol
):<br> def __init__(self):<br> self.output = None<br> self.normalizeNewlines = False<br><br> def dataReceived(self, data):<br> if self.normalizeNewlines:<br> data = re.sub(r"(\r\n|\n)", "\r\n", data)
<br> if self.output:<br> self.output.write(data)<br><br>class StdioProxyProtocol(DataForwardingProtocol):<br> def connectionMade(self):<br> inputForwarder = DataForwardingProtocol()<br>
inputForwarder.output = self.transport<br> inputForwarder.normalizeNewlines = True<br> stdioWrapper = stdio.StandardIO(inputForwarder)<br> self.output = stdioWrapper<br> print "Connected to server. Press ctrl-C to close connection."
<br><br>class StdioProxyFactory(protocol.ClientFactory):<br> protocol = StdioProxyProtocol<br><br> def clientConnectionLost(self, transport, reason):<br> reactor.stop()<br><br> def clientConnectionFailed(self, transport, reason):
<br> print reason.getErrorMessage()<br> reactor.stop()<br><br>if __name__ == '__main__':<br> import sys<br> if not len(sys.argv) == 3:<br> print "Usage: %s host port" % __file__<br>
sys.exit(1)<br> <br> reactor.connectTCP(sys.argv[1], int(sys.argv[2]), StdioProxyFactory())<br> reactor.run()<br>-----------------------------------------------------------------------<br><br> Thanks in advance.
<br><br> Mike<br>Aug. 3, 2006<br><br><br>