code: def connect(self,
                  uri=None,
                  cleansession=None,
                  cafile=None,
                  capath=None,
                  cadata=None,
                  extra_headers={}):
          
  
          self.session = self._initsession(uri, cleansession, cafile, capath, cadata)
          self.extra_headers = extra_headers;
          self.logger.debug("Connect to: %s" % uri)
  
          try:
              return (yield from self._do_connect())
          except BaseException as be:
              self.logger.warning("Connection failed: %r" % be)
              auto_reconnect = self.config.get('auto_reconnect', False)
              if not auto_reconnect:
                  raise
              else:
                  return (yield from self.reconnect())
docs: Connect to a remote broker.
  
              At first, a network connection is established with the server using the given protocol (``mqtt``, ``mqtts``, ``ws`` or ``wss``). Once the socket is connected, a `CONNECT <http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718028>`_ message is sent with the requested informations.
  
              This method is a *coroutine*.
  
              :param uri: Broker URI connection, conforming to `MQTT URI scheme <https://github.com/mqtt/mqtt.github.io/wiki/URI-Scheme>`_. Uses ``uri`` config attribute by default.
              :param cleansession: MQTT CONNECT clean session flag
              :param cafile: server certificate authority file (optional, used for secured connection)
              :param capath: server certificate authority path (optional, used for secured connection)
              :param cadata: server certificate authority data (optional, used for secured connection)
              :param extra_headers: a dictionary with additional http headers that should be sent on the initial connection (optional, used only with websocket connections)
              :return: `CONNACK <http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718033>`_ return code
              :raise: :class:`hbmqtt.client.ConnectException` if connection fails