&gt;Assuming that your python program is connected to your two<br>&gt;devices with two independent TCP connections, your python<br>&gt;program actually is doing message based routing among two<br>&gt;async bi-directional tcp channels.
<br><br>This is a very good way to describe it, thank you.<br><br>&gt;Four extra threads is four more than there&#39;s any reason to have here.&nbsp;&nbsp;Two<br>&gt;threads per socket is the kind of thing Twisted exists to let you avoid.
<br><br>Even with asyncore I don&#39;t need two threads per connection. The asyncore loop handles the send and receive just fine. My Queue interface between my application and the comms layer is what I need a protocol for. Abstractly, it isn&#39;t complicated, I just don&#39;t have time to go down that road without any guidance because if it takes more then a day or two I&#39;m toast.
<br><br>I&#39;m more interested in a mapping from asyncore dispatcher to twisted protocol. This is on my to do list to figure out but for my current project i don&#39;t have time. Something filling in these blanks would be perfect:
<br><br>Asyncore.dispatcher -----&gt;Twisted Protocol<br>handle_connect ------------&gt; ?<br>handle_read&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ------------&gt; read, getline, readraw, etc...<br>handle_write&nbsp;&nbsp;&nbsp;&nbsp; ------------&gt; sendline, send, etc...<br>
handle_expt&nbsp;&nbsp;&nbsp;&nbsp; ------------&gt; ?<br>?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -------------&gt; buildFactory<br>asyncore.loop&nbsp; ------------&gt; reactor.run<br><br>Obviously need more then just that.<br><br>I have found the online examples and documentation to be quite terse when describing how things fit together. When I eventually get the chance to make this migration I plan to write a tutorial. In my opinion the less legacy code directly using asyncore in this world, the better, so may as well make it easy to migrate.
<br><br>Sean<br><br><div><span class="gmail_quote">On 3/14/07, <b class="gmail_sendername">Jean-Paul Calderone</b> &lt;<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wed, 14 Mar 2007 00:26:23 -0700, jian wu &lt;<a href="mailto:hellojianwu@gmail.com">hellojianwu@gmail.com</a>&gt; wrote:<br>&gt;Hi Sean,<br>&gt;&gt;I am actually not sure if it is my protocol that is complicated<br>&gt;&gt;or if the way in which I want to pass the data that is complicated.
<br>&gt;<br>&gt;I should claim that I&#39;m not very well experienced with either Twisted<br>&gt;or asyncore, My guess is that is not protocol but the way to pass<br>&gt;data.<br>&gt;<br>&gt;Assuming that your python program is connected to your two
<br>&gt;devices with two independent TCP connections, your python<br>&gt;program actually is doing message based routing among two<br>&gt;async bi-directional tcp channels.<br>&gt;<br>&gt;My guess is that you can keep two Queues since it will help
<br>&gt;keeping the order of the async messages received and processed.<br>&gt;And, since twisted has a thread pool, it might be doable that<br>&gt;you could create four threads, two for each TCP Connections,<br>&gt;one thread for read and another for write per TCP connection,
<br>&gt;the read thread will handle the received message, process it<br>&gt;and put it into the Queue, the write thread will take the message<br>&gt;from the Queue and write it out to the targeted TCP connection.<br>&gt;<br>
<br>Four extra threads is four more than there&#39;s any reason to have here.&nbsp;&nbsp;Two<br>threads per socket is the kind of thing Twisted exists to let you avoid.<br><br>Jean-Paul<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">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
</a><br></blockquote></div><br><br clear="all"><br>-- <br><br>Sean Roark