[Twisted-Python] Multiple clients

Szabolcs Balogh bszabolcs at gmail.com
Fri Jun 18 11:55:49 MDT 2010


On Friday 18 June 2010 20:25:50 Itamar Turner-Trauring wrote:
> > It sounds good, but if I don't call reactor.run() after connectSSL
> > doesn't happens anything... If I call reactor.run() after connectSSL, it
> > works properly...
> 
> There are two types of client connections:
> 
> 1. Connections you open when you first run the program. Call these before
> reactor.run() is called.
> 
> 2. Connections that happen as result of events. Events are all dispatched
> by the reactor, so e.g. gui click or data received over network connection
> will result in functions being called by the reactor.  These functions can
> also open new connections.
> 
> The key here is to distinguish between the order of the code in the text
> file, and the order the code runs in. In the following example, the
> connectTCP will happen *after* reactor.run():
> 
> 
> # this will get called 10 seconds after reactor.run():
> def happensLater():
>     reactor.connectTCP(....)
> 
> reactor.callLater(10, happensLater)
> reactor.run()
> 
> 
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

It is possible to:
 - start the reactor when I initialize my program (eg. in main)
 - call connectTCP or connectSSL when I want and every time I want?

Something like this:

def check_messages(account):
	# connect to imap server and check for new mailboxes/messages
	reactor.connectSSL(...)


if __name__ == "__main__":
	reactor.run()

	check_message(account1)
	check_message(account2)
	...
	do something else
	...
	check_message(accountn)


Because I can't implement this :}

I have started the implementation based on "Twisted Network Programming 
Essential", but this book doesn't treat multiple connections...




More information about the Twisted-Python mailing list