Hi all,<br>&nbsp;&nbsp;&nbsp;&nbsp; I'm learning Twisted by reading Abe Fettig's &quot;Twisted Networking Programming Essentials&quot;. I tried the example 2-6 (dataforward.py) but the program hung after printing 'Connected to ...'. I don't know&nbsp; 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>&nbsp;&nbsp;&nbsp; def __init__(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.output = None<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.normalizeNewlines = False<br><br>&nbsp;&nbsp;&nbsp; def dataReceived(self, data):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.normalizeNewlines:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data = re.sub(r&quot;(\r\n|\n)&quot;, &quot;\r\n&quot;, data)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.output:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.output.write(data)<br><br>class StdioProxyProtocol(DataForwardingProtocol):<br>&nbsp;&nbsp;&nbsp; def connectionMade(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inputForwarder = DataForwardingProtocol()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
inputForwarder.output = self.transport<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inputForwarder.normalizeNewlines = True<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stdioWrapper = stdio.StandardIO(inputForwarder)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.output = stdioWrapper<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Connected to server.&nbsp; Press ctrl-C to close connection.&quot;
<br><br>class StdioProxyFactory(protocol.ClientFactory):<br>&nbsp;&nbsp;&nbsp; protocol = StdioProxyProtocol<br><br>&nbsp;&nbsp;&nbsp; def clientConnectionLost(self, transport, reason):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.stop()<br><br>&nbsp;&nbsp;&nbsp; def clientConnectionFailed(self, transport, reason):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print reason.getErrorMessage()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.stop()<br><br>if __name__ == '__main__':<br>&nbsp;&nbsp;&nbsp; import sys<br>&nbsp;&nbsp;&nbsp; if not len(sys.argv) == 3:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Usage: %s host port&quot; % __file__<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
sys.exit(1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; reactor.connectTCP(sys.argv[1], int(sys.argv[2]), StdioProxyFactory())<br>&nbsp;&nbsp;&nbsp; reactor.run()<br>-----------------------------------------------------------------------<br><br>&nbsp;&nbsp; Thanks in advance.
<br><br>&nbsp;&nbsp; Mike<br>Aug. 3, 2006<br><br><br>