Kiran
Kiran

Reputation: 8548

Twisted : How to print message at the server?

I am a beginner using Twisted framework.

I am developing a simple client server program using twisted library in Python.

I am using the code at the server side.

factory = protocol.ServerFactory()
factory.protocol = Echo
PortNo = 8000
reactor.listenTCP(PortNo,factory)

reactor.run()

I would like to print the message at the server side, whenever the client closes the connection.

Any idea how to do it ?

Thanks

Upvotes: 1

Views: 120

Answers (1)

acj
acj

Reputation: 134

Extend the connectionLost method of the protocol that you want to use.

def connectionLost(self, reason): 
   self.factory.numProtocols = self.factory.numProtocols-1
   // do stuff

For more references:

http://twistedmatrix.com/documents/12.2.0/core/howto/servers.html#auto2

Upvotes: 4

Related Questions