cohorte / cohorte-herald

An easy-to-use messaging framework
Apache License 2.0
3 stars 5 forks source link

Check/recheck connection to XMPP server #13

Open debbabi opened 9 years ago

debbabi commented 9 years ago

Line: 162 https://github.com/isandlaTech/cohorte-herald/blob/master/python/herald/transports/xmpp/transport.py#L162

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 9 years ago

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 9 years ago

Looking at the Event Index of SleekXMPP, the following ones could give hints about connection failures: