<br><br><div class="gmail_quote">On Tue, Sep 27, 2011 at 1:55 PM, David Kao <span dir="ltr"><<a href="mailto:a.libran@gmail.com">a.libran@gmail.com</a>></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't this client just try to connect and act accordingly if there is no server listening?<br>
<br>It'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. <<a href="mailto:enriquejr@gmail.com">enriquejr@gmail.com</a>> wrote:<br>
> On Tue, Sep 27, 2011 at 5:28 PM, David Kao <<a href="mailto:a.libran@gmail.com">a.libran@gmail.com</a>> wrote:<br>
>><br>
>> I have an existing program that connects to a TCP port to serve data. I<br>
>> need to<br>
>><br>
>> 1) start a TCPServer<br>
>><br>
>> 2) start my program and tell it which port to connect to<br>
><br>
> In case you already did, you might want to take a deeper look again at the<br>
> Twisted Core Documentation. The Writing a TCP Server section answers your<br>
> question #1, Writing a TCP Client section answers your question #2.<br>
><br>
>><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<br>
>> ),setServiceParent(serviceCollection)<br>
><br>
> Of course you can do all these in twisted. But in this context, it doesn't<br>
> make sense to run both in the same twisted application.<br>
><br>
>><br>
>> I revise my question.<br>
>><br>
>> Can I rely on reactor.listenTCP being called right after<br>
>> serverFactory.startFactory is called?<br>
>><br>
>> I hope listenTCP isn't queued as a reactor "task" after<br>
>> serverFactory.startFactory. If it's done all in one uninterrupted<br>
>> thread execution, then I can just queue "start_the_other_program"<br>
>> inside startFactory via a reactor.callLater. Correct?<br>
><br>
> The reverse is what is guaranteed: serverFactory.startFactory will be called<br>
> when you do reactor.listenTCP.<br>
><br>
>><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>
><br>
> You can find it here.<br>
><br>
>><br>
>> Thanks!<br>
>><br>
>> David Kao<br>
>><br>
><br>
> --Enrique<br>
><br>
><br>
</div></div><div><div></div><div class="h5">> _______________________________________________<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>
><br>
><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>