'Create a new socket and connect to the server.
Setting ``reattempt`` to ``True`` will cause connection
attempts to be made with an exponential backoff delay (max of
:attr:`reconnect_max_delay` which defaults to 10 minute) until a
successful connection is established.
:param host: The name of the desired server for the connection.
:param port: Port to connect to on the server.
:param use_ssl: Flag indicating if SSL should be used by connecting
directly to a port using SSL.
:param use_tls: Flag indicating if TLS should be used, allowing for
connecting to a port without using SSL immediately and
later upgrading the connection.
:param reattempt: Flag indicating if the socket should reconnect
after disconnections.'

def connect(self, host=u'', port=0, use_ssl=False, use_tls=True, reattempt=True):

    self.stop.clear()
    if (host and port):
        self.address = (host, int(port))
    try:
        Socket.inet_aton(self.address[0])
    except (Socket.error, ssl.SSLError):
        self.default_domain = self.address[0]
    if (use_ssl is not None):
        self.use_ssl = use_ssl
    if (use_tls is not None):
        self.use_tls = use_tls
    attempts = self.reconnect_max_attempts
    connected = self.state.transition(u'disconnected', u'connected', func=self._connect, args=(reattempt,))
    while (reattempt and (not connected) and (not self.stop.is_set())):
        connected = self.state.transition(u'disconnected', u'connected', func=self._connect)
        if (not connected):
            if (attempts is not None):
                attempts -= 1
                if (attempts <= 0):
                    self.event(u'connection_failed', direct=True)
                    return False
    return connected
