Source is https://stackoverflow.com/a/49452683/1504003
with small adaptations (reset delay and retries when we get back a
connection)
Instead of creating the connection in the "main" method, loop and reopen
a new event loop on failures, let the Protocol class handle connections
and retries on failures.
Reduce keepalive interval and store values in attributes. As many
timeouts in systems are 60 seconds, a keepalive of 50 seconds is less
likely to be stopped.
Improve logs: the docstring of connection_lost is:
The argument is either an exception object or None. The latter means a
regular EOF is received, or the connection was aborted or closed by this
side of the connection.
When it receives no exception, it should not raise an error log.
The proxy would not exit properly in case of a lost connection with the JMIF server.
The change allows the proxy to exit, giving a chance to an external monitoring system
to restart the service.