1

Hello
I'm new in twisted, but have some questions after read manual:
1. How to use different protocols with different reactor in one program? (for example, txNetTools have own reactor and internal IRC support in twisted have own reactor from twisted.internet)
2. How to start more one client in one time? (many client with ping to other remote host) http://bazaar.launchpad.net/~oubiwann/txnet/trunk/view/head:/sandbox/ping.py
3. How to put data from one protocol to other (in one program)? I'm want use data from database in protocol. (for example, every 5 minutes get hosts from database and create ping clients)
My task is simple, create a more different protocol client to many count of servers.

2 Answers 2

1

Well, for the third question at least, are you talking about using protocols of different classes or multiple protocol instances of the same class? Protocol instances can communicate between each other by having the factory that creates them store their data, like the following:

class p(Protocol): factory = None ... class f(Factory): protocol = p data = None def buildProtocol(self, addr): returnValue = p() returnValue.factory = self return returnValue 

From there you can save data to self.factory.data from within a protocol instance, and any other protocol instance can access it. I hope that answered your question.

Sign up to request clarification or add additional context in comments.

1 Comment

Big thx for answer. For example, I'm want use database connection factory and network factory. If I'm get data in database, I'm must move data to network Factory. I'm think - understand how this :) In database factory after get data call method in network factory.
1

How to use different protocols with different reactor in one program?

You don't. There is only one reactor per process, and it can handle as many connections as you want it to. The vast majority of libraries don't provide a reactor, and the reactor provided by txNetTools is optional. The only thing it provides is this method:

def listenICMP(self, port, protocol, interface="", maxPacketSize=8192): p = icmp.Port(port, protocol, interface, maxPacketSize, self) p.startListening() return p 

If you want to use another reactor, then you can just instantiate an icmp.Port yourself.

How to start more one client in one time?

The same way you start one, but repeated. For example, here's ten concurrent pingers (incorporating the answer to the first question):

for i in range(10): p = icmp.Port(0, Pinger(), reactor=reactor) p.startListening() reactor.run() 

chameco gives a fine answer to the last question.

1 Comment

Thx for answer. I'm all understand :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.