I use tornado 5.1
There is a socket iostream:
self.socket = socket.socket()
self.stream = tornado.iostream.IOStream(self.socket)
self.stream.connect((self.ip, self.port), self.connect_callback)
I need to reconnect it if it got WSAECONNREFUSED or any other error resulting it to be closed.
And ofc. if the connection is alive it does not to be reconnected. This procedure on attempting to reconnect must be executed only if the stream is closed.
Yes, the only is required is to make PeriodicCallback:
server = MainServer() # an instance of tornado.web.Application
server.listen(8888)
reconnect_periodic_callback = tornado.ioloop.PeriodicCallback(
server.reconnect_closed_clients, 5000
)
reconnect_periodic_callback.start()
tornado.ioloop.IOLoop.instance().start()