Thanks, Arjan.  Of course, factories are breeding like rabbits, but that was the obvious solution!  :-)  I wish I had thought of it.<br><br>You saved me several MORE hours...I&#39;ve spend all day on this. <br><br>(It&#39;s snowing and work was CLOSED!  Yeehah!)<br>
<br>Mark<br><br><div class="gmail_quote">On Wed, Feb 10, 2010 at 2:38 PM, Arjan Scherpenisse <span dir="ltr">&lt;<a href="mailto:arjan@scherpenisse.net">arjan@scherpenisse.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<br>
If you create two instances of your ClusterClientFactory, each with a<br>
unique string, you should be fine. Requires only a small modification:<br>
<div class="im"><br>
         factory = ClusterClientFactory()<br>
         factory.maxDelay = 120  #  two minutes<br>
         factory.connectString = &quot;FirstString...&quot;<br>
         reactor.connectTCP(&quot;localhost&quot;, 7300, factory)<br>
<br>
</div>         factory2 = ClusterClientFactory()<br>
         factory2.maxDelay = 120  #  two minutes<br>
         factory2.connectString = &quot;SecondString&quot;<br>
         reactor2.connectTCP(&quot;localhost&quot;, 7300, factory)<br>
<br>
You can clean this up by putting the maxDelay and connectString in the<br>
constructor of the factory:<br>
<br>
reactor2.connectTCP(&quot;localhost&quot;, 7300, ClusterClientFactory(120, &quot;First&quot;))<br>
reactor2.connectTCP(&quot;localhost&quot;, 7300, ClusterClientFactory(120, &quot;Second&quot;))<br>
<br>
Arjan<br>
<div><div></div><div class="h5"><br>
Mark Bailey wrote:<br>
&gt; Good day:<br>
&gt;<br>
&gt; I&#39;ve been having fun with Twisted.  I have my application running fine,<br>
&gt; with multiple server and client connections using Telnet.  :-)<br>
&gt;<br>
&gt; However, users always want something.  I need to send some unique<br>
&gt; configuration information to each connection.  The connections are made<br>
&gt; using connectTCP.  My first attempt assumed that the connection was made<br>
&gt; when the call to connectTCP was executed.  It didn&#39;t work!  :-(<br>
&gt;<br>
&gt; -------------------------------<br>
&gt;<br>
&gt; from twisted.internet.protocol import ClientFactory<br>
&gt; from twisted.internet import reactor<br>
&gt; from twisted.conch.telnet import StatefulTelnetProtocol<br>
&gt;<br>
&gt; class testClient(StatefulTelnetProtocol):<br>
&gt;<br>
&gt;     def connectionMade(self):<br>
&gt;         self.title = self.factory.connectString<br>
&gt;         print &quot;Client Connected: &quot; + self.title<br>
&gt;         self.setRawMode()<br>
&gt;         self.factory.connections.append(self)<br>
&gt;<br>
&gt;     def connectionLost(self, reason):<br>
&gt;         if self in self.factory.connections:<br>
&gt;             self.factory.connections.remove(self)<br>
&gt;<br>
&gt;     def rawDataReceived(self,data):<br>
&gt;         print data + &quot;\n&quot;<br>
&gt;<br>
&gt; class ClusterClientFactory(ClientFactory):<br>
&gt;<br>
&gt;     protocol = testClient<br>
&gt;<br>
&gt;     def __init__(self):<br>
&gt;         self.connections = []<br>
&gt;         self.connectString = &#39;&#39;<br>
&gt;<br>
&gt;     def startFactory(self):<br>
&gt;         print &quot;startFactory: &quot; + self.connectString<br>
&gt;<br>
&gt;     def startedConnecting(self, connector):<br>
&gt;         print &quot;Started connecting: &quot; + str(connector)<br>
&gt;         print self.connectString<br>
&gt;<br>
&gt;     def buildProtocol(self, addr):<br>
&gt;         print &quot;bulldProtocol: &quot; + str(addr)<br>
&gt;         print &quot;buildProtocol: &quot; + self.connectString<br>
&gt;<br>
&gt;         p = self.protocol()<br>
&gt;         p.factory = self<br>
&gt;         return p<br>
&gt;<br>
&gt; if __name__ == &#39;__main__&#39;:<br>
&gt;<br>
&gt;<br>
&gt;     def startUp():<br>
&gt;<br>
&gt;         factory = ClusterClientFactory()<br>
&gt;         factory.maxDelay = 120  #  two minutes<br>
&gt;<br>
&gt;         factory.connectString = &quot;FirstString...&quot;<br>
&gt;         reactor.connectTCP(&quot;localhost&quot;, 7300, factory)<br>
&gt;<br>
&gt;         factory.connectString = &quot;SecondString&quot;<br>
&gt;         reactor.connectTCP(&quot;localhost&quot;, 7300, factory)<br>
&gt;<br>
&gt;     reactor.callWhenRunning(startUp)<br>
&gt;     reactor.run()<br>
&gt;<br>
&gt; ----------------------------------<br>
&gt;<br>
&gt; The results are that buildProtocol gets the second string both times.<br>
&gt; startedConnecting gets the correct string, but all I have there is a<br>
&gt; connection object.  I need the correct data in buildProtocol to do it<br>
&gt; this way.<br>
&gt;<br>
&gt; ------------------------------------<br>
&gt;<br>
&gt; C:\Users\Mark\src\play&gt;python testclient.py<br>
&gt; startFactory: FirstString...<br>
&gt; Started connecting: &lt;twisted.internet.tcp.Connector instance at 0x01DAB620&gt;<br>
&gt; FirstString...<br>
&gt; Started connecting: &lt;twisted.internet.tcp.Connector instance at 0x01E0EFD0&gt;<br>
&gt; SecondString<br>
&gt; bulldProtocol: IPv4Address(TCP, &#39;127.0.0.1&#39;, 7300)<br>
&gt; buildProtocol: SecondString<br>
&gt; Client Connected: SecondString<br>
&gt; Welcome to SimpleServer5<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; bulldProtocol: IPv4Address(TCP, &#39;127.0.0.1&#39;, 7300)<br>
&gt; buildProtocol: SecondString<br>
&gt; Client Connected: SecondString<br>
&gt; Welcome to SimpleServer5<br>
&gt;<br>
&gt; --------------------------<br>
&gt;<br>
&gt;<br>
&gt; My &quot;best&quot; idea is to pass the strings to the factory in a dictionary<br>
&gt; indexed by the IP address and the port.  Then, buildProtocol() can use<br>
&gt; that to recover the string and I can use reactor.resolve() to translate<br>
&gt; the host name to the IP address.  The real application won&#39;t have<br>
&gt; multiple connections to the same host and port like this example, so<br>
&gt; this would work.<br>
&gt;<br>
&gt; There MUST be a better way.  :-)<br>
&gt;<br>
&gt; My &quot;simpleserver&quot; is below if you want to run this.<br>
&gt;<br>
&gt; THANKS for all of your help.  I have the basic application running now<br>
&gt; (including a Tkinter GUI  :-) ) and Twisted has saved me hundreds or<br>
&gt; even thousands of lines of code...<br>
&gt;<br>
&gt; Mark Bailey<br>
&gt;<br>
&gt; ------------------------------<br>
&gt;<br>
&gt; from twisted.conch.telnet import StatefulTelnetProtocol<br>
&gt; from twisted.internet import reactor, protocol<br>
&gt; from twisted.protocols.basic import LineReceiver<br>
&gt;<br>
&gt; class TelnetEcho(StatefulTelnetProtocol):<br>
&gt;     def connectionMade(self):<br>
&gt;         self.factory.connection.append(self)<br>
&gt;         self.sendLine(&quot;Welcome to SimpleServer5\r\n&quot;)<br>
&gt;<br>
&gt;<br>
&gt;     def lineReceived(self, data):<br>
&gt;         data = data.rstrip(&#39;\n\r&#39;)<br>
&gt;<br>
&gt;         if data.upper() == &#39;BYE&#39;:<br>
&gt;             self.sendLine(&quot;Goodbye...\r&quot;)<br>
&gt;             self.transport.loseConnection()<br>
&gt;         else:<br>
&gt;             self.sendLine(&quot;Unrecognized command: %r\r&quot; % (data,))<br>
&gt;<br>
&gt;     def connectionLost(self, reason):<br>
&gt;         self.factory.connection.remove(self)<br>
&gt;<br>
&gt;<br>
&gt; class TelnetEchoFactory(protocol.Factory):<br>
&gt;     protocol = TelnetEcho<br>
&gt;     def __init__(self):<br>
&gt;         self.connection = []<br>
&gt;<br>
&gt;<br>
&gt; def createTelnetServer(port=7300):<br>
&gt;     telnetinstance = TelnetEchoFactory()       #  needs to be a list<br>
&gt;     reactor.listenTCP(port,telnetinstance)<br>
&gt;<br>
&gt; if __name__ == &quot;__main__&quot;:<br>
&gt;     reactor.callWhenRunning(createTelnetServer)<br>
&gt;     reactor.run()<br>
&gt;<br>
&gt;<br>
</div></div>&gt; ------------------------------------------------------------------------<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Twisted-Python mailing list<br>
&gt; <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
&gt; <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v1.4.9 (GNU/Linux)<br>
Comment: Using GnuPG with Mozilla - <a href="http://enigmail.mozdev.org/" target="_blank">http://enigmail.mozdev.org/</a><br>
<br>
iEYEARECAAYFAktzC0MACgkQigE4AbflYer9nwCgixra0FaTD6ubvGJufjApRG/m<br>
A34An3C2ng+4x3/halWSgGQUvQvsCiTM<br>
=Cg6W<br>
-----END PGP SIGNATURE-----<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</blockquote></div><br>