[Twisted-Python] How could I distinguish each TCP connection?
radeex at gmail.com
Tue Jun 21 01:26:12 EDT 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)
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| |
More information about the Twisted-Python