code: def connect(self, app_id, wait=True, security=None):
          
          if wait:
              resp = self._call('waitForStart', proto.Application(id=app_id))
          else:
              resp = self._call('getStatus', proto.Application(id=app_id))
          report = ApplicationReport.from_protobuf(resp)
          if report.state is not ApplicationState.RUNNING:
              raise ApplicationNotRunningError(
                  "%s is not running. Application state: "
                  "%s" % (app_id, report.state))
  
          if security is None:
              security = self.security
  
          return ApplicationClient('%s:%d' % (report.host, report.port),
                                   app_id,
                                   security=security)
docs: Connect to a running application.
  
          Parameters
          ----------
          app_id : str
              The id of the application.
          wait : bool, optional
              If true [default], blocks until the application starts. If False,
              will raise a ``ApplicationNotRunningError`` immediately if the
              application isn't running.
          security : Security, optional
              The security configuration to use to communicate with the
              application master. Defaults to the global configuration.
  
          Returns
          -------
          app_client : ApplicationClient
  
          Raises
          ------
          ApplicationNotRunningError
              If the application isn't running.