Check/recheck connection to XMPP server
Opened this issue · 2 comments
debbabi commented
Fix by something like that one:
# Connect to the server
from time import sleep
tries_delay = 5
max_tries = 3
tries = range(max_tries)
connected = False
for tries_remaining in tries:
if self._bot.connect(self._host, self._port):
connected = True
break
else:
sleep(tries_delay)
if connected == False:
# if not self._bot.connect(self._host, self._port):
_logger.error("Can't connect to the XMPP server at %s port %s",
self._host, self._port)
tcalmant commented
Another solution could be to use a third argument in self._bot.connect()
, which is reattempt
(boolean).
In this case, it would also be necessary to add a reconnect_max_attempts
member to the self._bot
object to control the number of attempts.
self._bot.reconnect_max_attempts = 3
if not self._bot.connect(self._host, self._port, True):
_logger.error("Can't connect to the XMPP server at %s port %s",
self._host, self._port)
tcalmant commented
Looking at the Event Index of SleekXMPP, the following ones could give hints about connection failures:
- disconnected, regarding if the session ended before receiving this event
- connection_failed, from xmlstream.py@782