docs: function connectToMTLumberjackServer(endpoint, port, tenantOrSupertenantId, logmetToken, isSuperTenant, callback) {
      currentSequenceNumber = 0;
      currentAck = -1;
      previousAck = -1;
  
      var conn_options = {
          host: endpoint,
          port: port
      };
      socketWrapper = { state: State.CONNECTING };
      tlsSocket = tls.connect(conn_options, function() {
          if (tlsSocket.authorized) {
              logger.info('Successfully established a connection with Logmet');
  
              // Now that the connection has been established, let's perform the handshake with Logmet
              authenticate(tenantOrSupertenantId, logmetToken, isSuperTenant);
          } else {
              logger.error('Failed to establish a connection with Logmet: ' + tlsSocket.authorizationError);
              socketWrapper.state = State.DISCONNECTED;
              tlsSocket.destroy();
              if (!initialConnectionEstablished) {
                  callback('SSL connection with Logmet has not been authorized. ERROR: ' + tlsSocket.authorizationError, '');
              } else {
                  retryWithExponentialBackoff(retryFunction);
              }
          }
      });
      socketWrapper.socket = tlsSocket;
  
      retryFunction = connectToMTLumberjackServer.bind(this, endpoint, port, tenantOrSupertenantId, logmetToken, isSuperTenant, callback);
  
      // Define callbacks to handle the network communication with Logmet
  
      tlsSocket.setTimeout(INACTIVITY_TIMEOUT);
  
      tlsSocket.on('timeout', socketEventHandler.bind(socketWrapper, 'timeout'));
      tlsSocket.on('error', socketEventHandler.bind(socketWrapper , 'error'));
      tlsSocket.on('disconnect', socketEventHandler.bind(socketWrapper, 'disconnect'));
      tlsSocket.on('end', socketEventHandler.bind(socketWrapper, 'end'));
      tlsSocket.on('close', socketEventHandler.bind(socketWrapper, 'close'));
  
      var ackBuffer = Buffer.allocUnsafe(6);
      var ackPosition = 0;
  
      tlsSocket.on('data', function(data) {
          // We must have received part of an ACK from Logmet. Let's process it.
          var dataBuf = Buffer.from(data);
          dataBuf.copy(ackBuffer, ackPosition);
          ackPosition += dataBuf.length;
  
          if (ackPosition !== 6) {
              // We don't have a complete ACK message yet, so return and wait for the rest
              return;
          } else {
              // We now have a complete ACK message, so reset the position pointer in the ackBuffer and continue
              ackPosition = 0;
          }
  
          var version = ackBuffer[0];
          var type = ackBuffer[1];
          if (type != 65) {
              // Unknown ACK type
              logger.error('Received an unknown ACK type from Logmet: ' + String.fromCharCode(type));
          } else if (version == 48) {
              // Got a "0A" from Logmet, that is, an invalid combination of tenant id and password was used
              logger.error('Logmet indicated an unauthorized connection due to invalid credentials.');
              socketWrapper.state = State.DISCONNECTED;
              tlsSocket.destroy();
              if (!initialConnectionEstablished) {
                  callback('ERROR: Invalid Logmet credentials; check your tenant id and password.', '');
              }
              else {
                  retryWithExponentialBackoff(retryFunction);
              }
          } else if (version == 49) {
              // We got a '"1A"<ack_number>'. Let's read the ACK number.
              logger.debug('Reading ACK number');
              previousAck = currentAck;
              currentAck = ackBuffer.readInt32BE(2);
              logger.info('Last ACK received: ' + currentAck);
              if (currentAck == 0) {
                  // The connection has just been established.
  
                  // If this is a reconnection after a failure, let's check if there is unACKED data to be sent
                  if (unackedDataElements.length !== 0) {
                      for (var i = 0; i < unackedDataElements.length; i++) {
                          writeToSocket(unackedDataElements, i);
                      }
                  }
  
                  logger.info('Initialized the Logmet client. The Logmet handshake is complete.');
  
                  // Reset the retry delay, as we have just successfully connected.
                  RETRY_DELAY = INITIAL_RETRY_DELAY;
  
                  if (!initialConnectionEstablished) {
                      // Let's signal the constructor caller that the connection is established.
                      // We only notify the constructor caller when the first connection is established.
                      // We should NOT call back to the caller every time we reconnect due to an error.
                      initialConnectionEstablished = true;
                      callback('', {handshakeCompleted: true});
                  }
              } else {
                  // A data frame has been ACKed
                  if (socketWrapper.state === State.CONNECTED) {
                      unackedDataElements.splice(0, currentAck - previousAck);
                  }
              }
  
              socketWrapper.state = State.CONNECTED;
              processDataBuffer();
          } else {
              // Unknown ACK version
              logger.error('Received an unknown ACK version from Logmet: ' + String.fromCharCode(version));
          }
      });
  }