<br><br><div class="gmail_quote">On Tue, Sep 27, 2011 at 1:55 PM, David Kao <span dir="ltr">&lt;<a href="mailto:a.libran@gmail.com">a.libran@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

My bad for not being clear, but actually, the client program is a<br>
separate binary that I plan to spawn as a subprocess, which should<br>
connect to the server.<br>
<br>
Basically, the answer I am getting now is that I am never sure when<br>
the server starts listening on a port. I need to take it on faith that<br>
within 1 sec of running twistd the port is being listened. Or perhaps<br>
check it using netstat or something from the outside ... ugly.<br></blockquote><div><br>So, you want to be sure that the server is listening before trying to connect from an independent client? Why?<br>Shouldn&#39;t this client just try to connect and act accordingly if there is no server listening?<br>

<br>It&#39;s as if you want to be sure that <a href="http://www.google.com/">http://www.google.com/</a>  is up and will answer you.<br>Why not just type <a href="http://www.google.com/">http://www.google.com/</a>  in a browser? <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>
I have gone through almost the entire tutorial. I am looking for the<br>
**source code** for internet.TCPServer<br>
<font color="#888888"><br>
David Kao<br>
</font><div><div></div><div class="h5"><br>
<br>
<br>
On Tue, Sep 27, 2011 at 5:53 PM, Enrique Samson Jr. &lt;<a href="mailto:enriquejr@gmail.com">enriquejr@gmail.com</a>&gt; wrote:<br>
&gt; On Tue, Sep 27, 2011 at 5:28 PM, David Kao &lt;<a href="mailto:a.libran@gmail.com">a.libran@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; I have an existing program that connects to a TCP port to serve data. I<br>
&gt;&gt; need to<br>
&gt;&gt;<br>
&gt;&gt; 1) start a TCPServer<br>
&gt;&gt;<br>
&gt;&gt; 2) start my program and tell it which port to connect to<br>
&gt;<br>
&gt; In case you already did, you might want to take a deeper look again at the<br>
&gt; Twisted Core Documentation. The Writing a TCP Server section answers your<br>
&gt; question #1, Writing a TCP Client section answers your question #2.<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; Actually, I want to do all this in twistd. And now I am looking at<br>
&gt;&gt; something like this which is even a bigger headache<br>
&gt;&gt;<br>
&gt;&gt; internet.TCPServer( 4321, serverFactory<br>
&gt;&gt; ),setServiceParent(serviceCollection)<br>
&gt;<br>
&gt; Of course you can do all these in twisted. But in this context, it doesn&#39;t<br>
&gt; make sense to run both in the same twisted application.<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; I revise my question.<br>
&gt;&gt;<br>
&gt;&gt; Can I rely on reactor.listenTCP being called right after<br>
&gt;&gt; serverFactory.startFactory is called?<br>
&gt;&gt;<br>
&gt;&gt; I hope listenTCP isn&#39;t queued as a reactor &quot;task&quot; after<br>
&gt;&gt; serverFactory.startFactory. If it&#39;s done all in one uninterrupted<br>
&gt;&gt; thread execution, then I can just queue &quot;start_the_other_program&quot;<br>
&gt;&gt; inside startFactory via a reactor.callLater. Correct?<br>
&gt;<br>
&gt; The reverse is what is guaranteed: serverFactory.startFactory will be called<br>
&gt; when you do reactor.listenTCP.<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; Enrique, thanks for the link. I think I saw that too. I traced it<br>
&gt;&gt; since reactor.listenTCP returns a port, and so on and so forth.<br>
&gt;&gt;<br>
&gt;&gt; However, I have not been able to find code for internet.TCPServer. I<br>
&gt;&gt; would like to be able to trace the code top down. Can someone help?<br>
&gt;<br>
&gt; You can find it here.<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; Thanks!<br>
&gt;&gt;<br>
&gt;&gt; David Kao<br>
&gt;&gt;<br>
&gt;<br>
&gt; --Enrique<br>
&gt;<br>
&gt;<br>
</div></div><div><div></div><div class="h5">&gt; _______________________________________________<br>
&gt; Twisted-Python mailing list<br>
&gt; <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
&gt; <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
&gt;<br>
&gt;<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" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br>