On Wed, Jul 2, 2008 at 9:46 AM, Paul Wilson &lt;<a href="mailto:paulalexwilson@gmail.com">paulalexwilson@gmail.com</a>&gt; wrote:<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;">
Hi all,<br>
<br>
I&#39;m new to twisted but am having trouble getting my head around how to<br>
structure my application with this new approach.<br>
<br>
I&#39;m creating a server that accepts client connections and then drives<br>
the client according to a simple, line-oriented protocol. The server<br>
sends the request (1 line), and receives a single lined result. I&#39;d<br>
like the server to offer an API to generate the correct request lines<br>
to the client, and return the results (either blocking or<br>
asynchronously). So in effect, I have two event loops, one from the<br>
Network and one from whatever&#39;s sending the API requests (command<br>
line?).<br>
<br>
Can anyone offer any guidance on how to tie these two parts together?<br>
My instinct is to have the two event loops in separate threads and<br>
communicate through Queue.Queue, but that doesn&#39;t seem to follow the<br>
spirit of twisted. And I guess I&#39;d have to somehow tell the reactor to<br>
poll the Queue object for requests, and then dispatch it to the<br>
relevant method to send out to the client. I&#39;ve looked at<br>
threadedselectreactor but can&#39;t seem to find any decent documentation<br>
to even decide if it&#39;s write for what I want.<br>
<br>
Any advice would be much appreciated.<br>
<br>
Thanks,<br>
Paul<br>
</blockquote></div><br>If I understand your problem correctly (and I&#39;m not sure that I do, so keep that in mind), then what you probably want is something like a Twisted app using two Protocol objects (perhaps in two different &quot;services&quot;), one to talk to your clients, and one to talk to your API-generator-thingy (command line).&nbsp; Then you just need a way for these to communicate...someplace to store the state.&nbsp; A Queue.Queue is probably a good choice, but I&#39;m not entirely sure where you would put it.&nbsp; Try looking around for examples that have multiple services and see how they share state.&nbsp; I think the Twisted book might have something useful in this regard, though I don&#39;t have it with me ATM.<br>
<br>Perhaps wiser heads than mine will have better ideas/comments.<br><br>Kevin Horn<br>