[Twisted-Python] How could I distinguish each TCP connection?
Christopher Armstrong
radeex at gmail.com
Mon Jun 20 23:26:12 MDT 2005
On 6/21/05, Eric Hsu <nkeric at gmail.com> wrote:
> factory = Factory()
> factory.protocol = MyTCPService
> reactor.listenTCP(port1, factory)
> reactor.listenUDP(port2, MyUDPService())
>
> How could I get the protocol instance of each client and maintain them?
> Please tell me more details if you could, since I'm very very new to
> twisted :)
I suggest, instead of using the stock "Factory", making a subclass of
it with buildProtocol implemented like so:
def buildProtocol(self, addr):
p = Factory.buildProtocol(self, addr)
self.connections.append(p)
return p
Or similar (you'll have to define the 'connections' list yourself in
__init__). In the protocol's connectionLost, you could then remove the
protocol from that list.
--
Twisted | Christopher Armstrong: International Man of Twistery
Radix | -- http://radix.twistedmatrix.com
| Release Manager, Twisted Project
\\\V/// | -- http://twistedmatrix.com
|o O| |
w----v----w-+
More information about the Twisted-Python
mailing list