MiggyMan has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, bit of a quickie really but does anyone know of a way to implement keepalives in Net::Server (Prefork specifially), I'm in a situation where I want two daemon's to have a persistent connection to each other, the big problem I have is that when they're idle the connection will time out, as it should! Edit: Had a bit of an "obvious" moment, I don't need both servers to be... servers, one need only be a daemonised process that initiates a connection to the server and keeps it open, this has lead me to Net::Server::Daemonize, IO::Async::Timer::Periodic and IO::Async::Stream, the combination of which should allow me to accomplish my task :D

Replies are listed 'Best First'.
Re: keepalives with Net::Server
by sierpinski (Chaplain) on Jun 01, 2010 at 11:59 UTC
    Any reason why you can't send a keepalive signal every so often to sustain the connection? A kind of 'are you there' signal that you can trap if one daemon dies, but also use as a keepalive?

    Update: Re-reading this before coffee, ugh... what I mean is... send the other daemon a socket bit using IO::Socket or something like that to sustain it's existence? In other words, don't let them go idle long enough for the timeout to occur.
      That's pretty much what I want to do, what I'm lacking is the mechanism to send the keepalives on regular intervals since net::server is connection based (and thus has no timed event(s))
        That's where the IO::Socket can come into play. Have your daemon send a keepalive bit (it could be some symbol that would never occur in your normal data transmission) and have the other daemon listen for that, and if it finds it, just throw it away. But that communication would cause the connection to persist. Both daemons would have to do this to keep both of them alive. The transmission of even one bit should be enough, I'd think.