[Twisted-Python] Porting Apache Mina to Twisted

Godson Gera godson.g at gmail.com
Sun Dec 5 07:43:05 MST 2010

On Sun, Dec 5, 2010 at 4:07 PM, Umut Aydin <devnetwork at gmail.com> wrote:

> Hello everybody. Hope you have a good weekend.
> I'm trying to port my distributed job server project to twisted but I
> have a few questions.
> I just tested twisted with protocol.Protocol socket handler class and
> it seems like that it creates a new instance for each connection. I
> want to put those connection's ip addresses into an array. Where
> should I do that exactly?
> How can I get ip address and port information out of
> self.transport.getPeer()?

Each created protocol comes with a refrence to factory that is creating
them, which is a right place of doing all the inter protocol operations .
You can access it via factory attribute of protocol. So, in a typical
twisted program you can refer to the factory by doing self.factory in the
created protocol. You can define an array called peers in factory and access
it like self.factory.peers.

Check out buildProtocol() method of twisted factories to customize protcol

Yes, transport.getPeers() gives you the remote end host and port.

Thanks & Regards,
Godson Gera
Twisted Python India <http://blog.godson.in>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20101205/15971d73/attachment.html>

More information about the Twisted-Python mailing list