On Tue, Sep 27, 2011 at 5:28 PM, David Kao <[email protected]> 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
_______________________________________________
Twisted-Python mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to