Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: How do I make a tcp socket heartbeat?

by haukex (Archbishop)
on Oct 09, 2020 at 19:35 UTC ( [id://11122643]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How do I make a tcp socket heartbeat?
in thread How do I make a tcp socket heartbeat?

One way to do that is to place the Mojo::IOLoop->client call in a subroutine, as in sub reconnect { Mojo::IOLoop->client( ... ) }, make sure to call that sub once before starting the loop to set up the initial connection, and then, in the handler for the close event, do something like Mojo::IOLoop->timer( 2 => \&reconnect ); to call that subroutine to reestablish the connection. I very much suggest the timer call so as to not flood the server with connection attempts, and I would also recommend adding a counter variable so you can stop attempting to reconnect after a certain number of failed attempts.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11122643]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found