One thing that has been puzzling me is where is the best place to put 
application code.
<br>
<br>The case I am using is straightforward TCP server with client 
connections making simple requests and waiting for responses retrieved 
from database tables to be sent back.
<br>
<br>Reading the docs and looking at various examples provided in books and 
documentation has left me a bit confused.
<br>
<br>Is there a best practice for where application code should go - either 
the protcocol class or the factory class or somewhere else. Does it 
actually matter.
<br>
<br>Is there any downside to putting application code in the protocol or 
factory. What pitfalls are there for either approach.
<br>
<br>I see examples where application code appears in both classes, but the 
examples are very small so may not be indicative of what should be done.
<br>
<br>In the docs I see reference to most of the code will be written in the 
protocol class, but that seems to be referring to actually writing 
protocols not application code. It also says that when the protocol 
needs to call application code to make it a method call -&nbsp; not to mix 
protocol and application code. This could just mean creating some 
methods in the protocol class to handle the task.
<br>
<br>However, if the application code needs to run for 10-12 seconds looking 
up database tables and accumulating results and waiting on&nbsp; deferreds, 
should all this code reside in the protocol class or the factory.
<br>
<br>If I keep it in the protocol, then I already have my client connection 
to write back to. So that seems to be the place to keep the code.
<br>
<br>If I put the code in the factory, then I need to pass the client 
connection so it can write back to the client. Or is there another way 
of doing this I have missed.
<br>.
<br>The factory seems to be the place where other classes can be passed in 
and the protocol can call them via self.factory. That seems to imply 
that application code should be put into the factory, but I can&#39;t see 
any way of passing back information from deferred results to the call 
from protocol. It&#39;s ok if it was just a simple method call that returns 
a result, but if the code has to run a series of deferreds then it will 
be the called method that will have the result and it will need a means 
of writing this back to the client. I don&#39;t think I can signal the 
protocol to say I now have the result.Of course I could easily be 
mistaken. So please correct.
<br>
<br>Of course if I passs the client connection to the factory, then it can 
use this to write back. But that means passing around the client 
connection. Should I avoid doing that or is that not a problem.
<br>
<br>I hope I have explained myself clearly. I&#39;m just looking for some 
guidance and pointers to what is best to do or what is best to avoid.
<br>
<br>Regards
<br>
<br>John Aherne<br>