[Twisted-Python] How do I know the server from reactor.listenTCP already started listening?

Enrique Samson Jr. enriquejr at gmail.com
Tue Sep 27 03:53:05 MDT 2011


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<http://twistedmatrix.com/documents/current/core/howto/servers.html>section
answers your question #1, Writing
a TCP Client<http://twistedmatrix.com/documents/current/core/howto/clients.html>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<http://twistedmatrix.com/documents/current/core/howto/tutorial/index.html>
.


> Thanks!
>
> David Kao
>
>
--Enrique
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20110927/708f3277/attachment.html>


More information about the Twisted-Python mailing list