python - How different protocols interact with eachother in Twisted -


scenario I want two different protocols interact with each other:

A And B. Two different protocols will interact with the first A server and will retrieve some values, after retrieving the values ​​of IA, B will start interacting with the server.

Now my problem is that there is a great way for the initial B when A value is obtained.

Currently, I only have the initial B in the data processing function of A. But I do not think this is a great way.

What's my great way to do that the initialization of B is done by a flow controller or something similar, but there is no other protocol.

Is there a great way?

I'm just new to twist, I do not know much about knowing ....

Thank you very much!

It seems that you have passed the first hurdles - find that A and B How to Talk Absolutely It's good, because for most people it is the biggest ideological challenge to make it elegant , if you're after an approach that keeps your protocol different from the driving application code ( I.e., "business logic"), there are several options, I give an example of defragment based on one.

Let's consider two POP3 clients. If you want to receive a message list for the first time, then the second to get the first message from the resulting list. Twisted.internet import defer, protocol, twisted.mail.pop3 import this example from the Advanced POP3 client class messaging (object) to Diff __int_ (self, host, port, user, password)

 < code> Self.host = host self.port = port self.user = user self.password = password self.cc = client career (reactor, advanced POP3 client) connected Diif (self): "" "POP connect to the POP3 server Do and authenticate, which sets fire to the associated protocol example. "" ConnDeferred = self.cc.connect (self.host, self.port) f cbAuthenticate (proto): loginDeferred = proto.login (user, password) LoginDeferredkaddClallback (lambda overlooked: Protota) back login Direed connDeferred.addCallback (cbAuthenticate) returns Kanan Difrd DRF run (self): connDeferred = self.connect ( ) connDeferred.addClallback (self.cbFirstConnec Tion) back connDeferred def cbFirstConnection (self, firstProto): listDeferred = firstProto.listUID () def cbListed (uidList): connDeferred = self.connect () Diif cbconnected (secondProto): return Dusriproto. Retrieve (uidList [0]) connDeferred AddCallback (cbConnected) listDeferred.addClallback (cbListed) return list has been detected that if __name__ == '__main__': import system messagesdownloader (* sys.argv [1:]). Run () Reactor.Run ()  

Here, all logic regarding real recovery of a list of UIDs and the establishment of a new connection to receive the message is the actual protocol implementation ( Which is completely twisted). Defrades came back from almost all APIs, here it is allowed to add events, however your app wants.


Comments