2009/5/13 <a href="mailto:bbxx789_05ss@yahoo.com">bbxx789_05ss@yahoo.com</a> <span dir="ltr">&lt;<a href="mailto:bbxx789_05ss@yahoo.com">bbxx789_05ss@yahoo.com</a>&gt;</span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
Here is the server code:<div><div>-------------</div><div><div>from twisted.internet.protocol import Protocol, Factory</div><div>from twisted.internet import reactor</div><div>import sys</div><div><br></div><div>class MyServer(Protocol):</div>
<div>    def connectionMade(self):<br></div><div>        self.transport.write(&quot;Hello&quot;)</div><div><br></div><div>factory = Factory()</div><div>factory.protocol =  MyServer</div><div><br></div><div>reactor.listenTCP(2000, factory)<br>
</div><div>reactor.run()</div><div>-----------</div><div><br></div><div><br></div><div>Here is the client code:</div><div>--------------</div><div><div>from twisted.internet.protocol import Protocol,
 ClientCreator</div><div>from twisted.internet import reactor</div><div>import sys</div><div><br></div><div>class MyClient(Protocol):</div><div>    def dataReceived(self, data):</div><div>        sys.stdout.write(data)</div>
<div>        self.transport.loseConnection()</div><div>------------</div><div><br></div><div>What do I need to add to the client code to make it connect to the server?  I think the &quot;How To&quot; documentation is woefully inadequate.  For instance, it says this:</div>
<div><br></div><div>----</div><div><span style="font-family: Helvetica; font-size: 16px;"><p style="margin: 0px;">Here is a simple example:</p><pre style="border: thin solid black; padding: 1em; background-color: rgb(221, 221, 221);">
<span style="color: rgb(51, 51, 204); font-weight: bold;">from</span> <span>twisted</span>.<span>internet</span>.<span>protocol</span> <span style="color: rgb(51, 51, 204); font-weight: bold;">import</span> <span>Protocol</span>
<span style="color: rgb(51, 51, 204); font-weight: bold;">from</span> <span>sys</span> <span style="color: rgb(51, 51, 204); font-weight: bold;">import</span> <span>stdout</span>

<span style="color: rgb(51, 51, 204); font-weight: bold;">class</span> <span style="color: rgb(204, 0, 0);">Echo</span>(<span style="color: rgb(0, 0, 102); font-weight: bold;">Protocol</span>):
    <span style="color: rgb(51, 51, 204); font-weight: bold;">def</span> <span style="color: rgb(204, 0, 0);">dataReceived</span>(<span style="color: rgb(0, 0, 102); font-weight: bold;">self</span>, <span style="color: rgb(0, 0, 102); font-weight: bold;">data</span>):
        <span>stdout</span>.<span>write</span>(<span>data)</span></pre></span></div><div>------</div><div><br></div><div>Anyone who knows even a little bit of python should be able to recognize that that code does absolutely nothing.  </div>
</div></div></div></td></tr></tbody></table></blockquote></div><br><br>Greetings nameless-and-frustrated Twisted beginner!  Have a look at the echoclient.py example, which you can download here:<br><br><a href="http://twistedmatrix.com/projects/core/documentation/examples/index.html">http://twistedmatrix.com/projects/core/documentation/examples/index.html</a><br>
<br>Essentially you also need to create an EchoFactory and set it to run within a reactor (notice that your server example already does this).<br><br>Hope that helps,<br><br>~Adam<br>