code: public synchronized AbstractXMPPConnection connect() throws SmackException, IOException, XMPPException, InterruptedException {
          // Check if not already connected
          throwAlreadyConnectedExceptionIfAppropriate();
  
          // Reset the connection state
          initState();
          saslAuthentication.init();
          streamId = null;
  
          try {
              // Perform the actual connection to the XMPP service
              connectInternal();
  
              // If TLS is required but the server doesn't offer it, disconnect
              // from the server and throw an error. First check if we've already negotiated TLS
              // and are secure, however (features get parsed a second time after TLS is established).
              if (!isSecureConnection() && getConfiguration().getSecurityMode() == SecurityMode.required) {
                  throw new SecurityRequiredByClientException();
              }
          } catch (SmackException | IOException | XMPPException | InterruptedException e) {
              instantShutdown();
              throw e;
          }
  
          // Make note of the fact that we're now connected.
          connected = true;
          callConnectionConnectedListener();
  
          return this;
      }
docs: Establishes a connection to the XMPP server. It basically
  creates and maintains a connection to the server.
  <p>
  Listeners will be preserved from a previous connection.
  </p>
  
  @throws XMPPException if an error occurs on the XMPP protocol level.
  @throws SmackException if an error occurs somewhere else besides XMPP protocol level.
  @throws IOException
  @return a reference to this object, to chain <code>connect()</code> with <code>login()</code>.
  @throws InterruptedException