>Assuming that your python program is connected to your two<br>>devices with two independent TCP connections, your python<br>>program actually is doing message based routing among two<br>>async bi-directional tcp channels.
<br><br>This is a very good way to describe it, thank you.<br><br>>Four extra threads is four more than there's any reason to have here. Two<br>>threads per socket is the kind of thing Twisted exists to let you avoid.
<br><br>Even with asyncore I don'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't complicated, I just don't have time to go down that road without any guidance because if it takes more then a day or two I'm toast.
<br><br>I'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't have time. Something filling in these blanks would be perfect:
<br><br>Asyncore.dispatcher ----->Twisted Protocol<br>handle_connect ------------> ?<br>handle_read ------------> read, getline, readraw, etc...<br>handle_write ------------> sendline, send, etc...<br>
handle_expt ------------> ?<br>? -------------> buildFactory<br>asyncore.loop ------------> 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> <<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>> 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 <<a href="mailto:hellojianwu@gmail.com">hellojianwu@gmail.com</a>> wrote:<br>>Hi Sean,<br>>>I am actually not sure if it is my protocol that is complicated<br>>>or if the way in which I want to pass the data that is complicated.
<br>><br>>I should claim that I'm not very well experienced with either Twisted<br>>or asyncore, My guess is that is not protocol but the way to pass<br>>data.<br>><br>>Assuming that your python program is connected to your two
<br>>devices with two independent TCP connections, your python<br>>program actually is doing message based routing among two<br>>async bi-directional tcp channels.<br>><br>>My guess is that you can keep two Queues since it will help
<br>>keeping the order of the async messages received and processed.<br>>And, since twisted has a thread pool, it might be doable that<br>>you could create four threads, two for each TCP Connections,<br>>one thread for read and another for write per TCP connection,
<br>>the read thread will handle the received message, process it<br>>and put it into the Queue, the write thread will take the message<br>>from the Queue and write it out to the targeted TCP connection.<br>><br>
<br>Four extra threads is four more than there's any reason to have here. 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