This is a follow-up to my previous question.
I am building a simple client server program using ´twisted´ package in Python.
I would like to keep a record of which client has joined and closed the connection.
Suppose, if Client B closes the connection, I would like to print at the server "Client B has closed the connection"
Here is the code I am using :
factory = protocol.ServerFactory()
factory.protocol = Echo
PortNo = 8000
reactor.listenTCP(PortNo,factory)
reactor.run()
def connectionLost(self, reason):
print "Connection lost"
Any idea how to do it ?
Thanks
The connection which was lost is the one associated with the protocol instance referenced by the
self
argument toconnectionLost
.With a normal factory (like
ServerFactory
, as you are using) there is a one to one relationship between connections and protocol instances.