[Twisted-Python] How do I know the server from reactor.listenTCP already started listening?
David Kao
a.libran at gmail.com
Tue Sep 27 04:55:34 MDT 2011
My bad for not being clear, but actually, the client program is a
separate binary that I plan to spawn as a subprocess, which should
connect to the server.
Basically, the answer I am getting now is that I am never sure when
the server starts listening on a port. I need to take it on faith that
within 1 sec of running twistd the port is being listened. Or perhaps
check it using netstat or something from the outside ... ugly.
I have gone through almost the entire tutorial. I am looking for the
**source code** for internet.TCPServer
David Kao
On Tue, Sep 27, 2011 at 5:53 PM, Enrique Samson Jr. <enriquejr at gmail.com> wrote:
> On Tue, Sep 27, 2011 at 5:28 PM, David Kao <a.libran at gmail.com> wrote:
>>
>> I have an existing program that connects to a TCP port to serve data. I
>> need to
>>
>> 1) start a TCPServer
>>
>> 2) start my program and tell it which port to connect to
>
> In case you already did, you might want to take a deeper look again at the
> Twisted Core Documentation. The Writing a TCP Server section answers your
> question #1, Writing a TCP Client section answers your question #2.
>
>>
>> Actually, I want to do all this in twistd. And now I am looking at
>> something like this which is even a bigger headache
>>
>> internet.TCPServer( 4321, serverFactory
>> ),setServiceParent(serviceCollection)
>
> Of course you can do all these in twisted. But in this context, it doesn't
> make sense to run both in the same twisted application.
>
>>
>> I revise my question.
>>
>> Can I rely on reactor.listenTCP being called right after
>> serverFactory.startFactory is called?
>>
>> I hope listenTCP isn't queued as a reactor "task" after
>> serverFactory.startFactory. If it's done all in one uninterrupted
>> thread execution, then I can just queue "start_the_other_program"
>> inside startFactory via a reactor.callLater. Correct?
>
> The reverse is what is guaranteed: serverFactory.startFactory will be called
> when you do reactor.listenTCP.
>
>>
>> Enrique, thanks for the link. I think I saw that too. I traced it
>> since reactor.listenTCP returns a port, and so on and so forth.
>>
>> However, I have not been able to find code for internet.TCPServer. I
>> would like to be able to trace the code top down. Can someone help?
>
> You can find it here.
>
>>
>> Thanks!
>>
>> David Kao
>>
>
> --Enrique
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>
More information about the Twisted-Python
mailing list