On Tue, Sep 27, 2011 at 5:28 PM, David Kao <span dir="ltr">&lt;<a href="mailto:a.libran@gmail.com">a.libran@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I have an existing program that connects to a TCP port to serve data. I need to<br>
<br>
1) start a TCPServer </blockquote><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
2) start my program and tell it which port to connect to<br></blockquote><div><br>In case you already did, you might want to take a deeper look again at the Twisted Core Documentation. The <a href="http://twistedmatrix.com/documents/current/core/howto/servers.html">Writing a TCP Server</a> section answers your question #1, <a href="http://twistedmatrix.com/documents/current/core/howto/clients.html">Writing a TCP Client</a> section answers your question #2.<br>
 </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
Actually, I want to do all this in twistd. And now I am looking at<br>
something like this which is even a bigger headache<br>
<br>
internet.TCPServer( 4321, serverFactory ),setServiceParent(serviceCollection)<br></blockquote><div>Of course you can do all these in twisted. But in this context, it doesn&#39;t make sense to run both in the same twisted application.<br>
 </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
I revise my question.<br>
<br>
Can I rely on reactor.listenTCP being called right after<br>
serverFactory.startFactory is called? </blockquote><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
I hope listenTCP isn&#39;t queued as a reactor &quot;task&quot; after<br>
serverFactory.startFactory. If it&#39;s done all in one uninterrupted<br>
thread execution, then I can just queue &quot;start_the_other_program&quot;<br>
inside startFactory via a reactor.callLater. Correct?<br></blockquote><div>The reverse is what is guaranteed: serverFactory.startFactory will be called when you do reactor.listenTCP.<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<br>
Enrique, thanks for the link. I think I saw that too. I traced it<br>
since reactor.listenTCP returns a port, and so on and so forth.<br>
<br>
However, I have not been able to find code for internet.TCPServer. I<br>
would like to be able to trace the code top down. Can someone help?<br></blockquote><div>You can find it <a href="http://twistedmatrix.com/documents/current/core/howto/tutorial/index.html">here</a>.<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

Thanks!<br>
<font color="#888888"><br>
David Kao<br>
</font><div><div></div><div class="h5"><br></div></div></blockquote><br>--Enrique<br><br></div>