[Twisted-Python] Sending a "good-bye message" before closing a connection

Hi! We have a small heartbeat-system based on Twisted. The clients register at the server and send some health information in regular intervals. If the server does not get a lifesign from a client, this is registered in a database. But sometimes, the clients have to go offline. In this case, I'd like them to send a message to the server that they will be gone for a while. When a client goes offline, the twistd daemon for handling the heartbeats is shut down. What is the best way to do this in Twisted? The `clientConnectionLost` method of the factory is only called after disconnecting, AFAICT. Thanks & best regards, -- Albert Brandl A-4813 Altmünster - Abteistraße 12 - web: www.weiermayer.com - phone: +43761287677 - fax: +43761220356 - mobile: +436642442777

On Fri, 2011-11-18 at 12:23 +0100, Albert Brandl wrote:
Presumably there is a method somewhere that decides to close the connection down: def timeToShutdown(self): self.transport.loseConnection() So instead do: def timeToShutdown(self): self.transport.write(GOODBYE) self.transport.loseConnection()

Hi! On Fri, Nov 18, 2011 at 08:31:18AM -0500, Itamar Turner-Trauring wrote:
Actually, I hoped that I'd find such a method in the framework. When the twistd daemon is shut down, it has to close all connections, and it would have been nice if there were a hook that could be overridden. But AFAICT, the respective code is buried inside the BaseConnector class, and I'd rather leave it alone :-). Anyway - it should be possible to send some kind of message to the daemon in the init script before shutting it down. Thanks & best regards, -- Albert Brandl | Weiermayer Solutions GmbH A-4813 Altmünster - Abteistraße 12 - web: www.weiermayer.com - phone: +43761287677 - fax: +43761220356 - mobile: +436642442777

On 10:13 am, albert.brandl@weiermayer.com wrote:
The shutdown hook provided is IService.stopService. You can add your custom shutdown logic there, and attach your service to the Application/Service hierarchy. Jean-Paul

On Fri, 2011-11-18 at 12:23 +0100, Albert Brandl wrote:
Presumably there is a method somewhere that decides to close the connection down: def timeToShutdown(self): self.transport.loseConnection() So instead do: def timeToShutdown(self): self.transport.write(GOODBYE) self.transport.loseConnection()

Hi! On Fri, Nov 18, 2011 at 08:31:18AM -0500, Itamar Turner-Trauring wrote:
Actually, I hoped that I'd find such a method in the framework. When the twistd daemon is shut down, it has to close all connections, and it would have been nice if there were a hook that could be overridden. But AFAICT, the respective code is buried inside the BaseConnector class, and I'd rather leave it alone :-). Anyway - it should be possible to send some kind of message to the daemon in the init script before shutting it down. Thanks & best regards, -- Albert Brandl | Weiermayer Solutions GmbH A-4813 Altmünster - Abteistraße 12 - web: www.weiermayer.com - phone: +43761287677 - fax: +43761220356 - mobile: +436642442777

On 10:13 am, albert.brandl@weiermayer.com wrote:
The shutdown hook provided is IService.stopService. You can add your custom shutdown logic there, and attach your service to the Application/Service hierarchy. Jean-Paul
participants (3)
-
Albert Brandl
-
exarkun@twistedmatrix.com
-
Itamar Turner-Trauring