CometD connect
CometD connect, see https://docs.cometd.org/current/reference/#_bayeux_meta_connect
@return ApiResponse&lt;Void&gt;
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
762756
public ApiResponse<Void> connectWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = connectValidateBeforeCall(null, null);
        return apiClient.execute(call);
    }
335905
public static function doConnect()
        {
            if (!\class_exists('\\PDO')) {
                throw new Exception('B2DB needs the PDO PHP libraries installed. See http://php.net/PDO for more information.');
            }
            try {
                $uname = self::getUsername();
                $pwd = self::getPassword();
                $dsn = self::getDSN();
                if (self::$db_connection instanceof PDO) {
                    self::$db_connection = null;
                }
                self::$db_connection = new PDO($dsn, $uname, $pwd);
                if (!self::$db_connection instanceof PDO) {
                    throw new Exception('Could not connect to the database, but not caught by PDO');
                }
        switch (self::getDriver())
        {
            case self::DRIVER_MYSQL:
                self::getDBLink()->query('SET NAMES UTF8');
                break;
            case self::DRIVER_POSTGRES:
                self::getDBlink()->query('set client_encoding to UTF8');
                break;
        }
            } catch (PDOException $e) {
                throw new Exception("Could not connect to the database [" . $e->getMessage() . "], dsn: ".self::getDSN());
            } catch (Exception $e) {
                throw $e;
            }
        }
281720
public function readAll()
    {
        $resourcesGetMethod = $this->resourcesGetMethod;
        if (!is_null($resourcesGetMethod)) {
            foreach ($this->call->responses() as $response) {
                foreach ($response->$resourcesGetMethod() as $resource) {
                    yield $resource;
                }
            }
        } else {
            foreach ($this->call->responses() as $response) {
                yield $response;
            }
        }
        $status = $this->call->getStatus();
        if (!($status->code == Code::OK)) {
            throw ApiException::createFromStdClass($status);
        }
    }
1251676
public function connect() {
        if (!function_exists('\pg_connect')) throw new RuntimeException('Undefined function pg_connect(), pgsql extension is not available');

        $connStr = $this->getConnectionString();
        try {
            $php_errormsg = '';
            $this->hConnection = pg_connect($connStr, PGSQL_CONNECT_FORCE_NEW);
            !$this->hConnection && trigger_error($php_errormsg, E_USER_ERROR);
        }
        catch (\Exception $ex) {
            if (!$ex instanceof IRosasurferException)
                $ex = new DatabaseException($ex->getMessage(), $ex->getCode(), $ex);
            throw $ex->addMessage('Cannot connect to PostgreSQL server with connection string: "'.$connStr.'"');
        }

        $this->setConnectionOptions();
        return $this;
    }
184928
public function connect()
    {
        if ($this->connection) {
            return $this;
        }

        $dsn = PdoHelper::getDsn($this->options['driver'], $this->options);

        try {
            $this->connection = new \PDO(
                $dsn,
                $this->options['user'],
                $this->options['password'],
                $this->options['driverOptions']
            );
        } catch (\PDOException $e) {
            throw new \RuntimeException(
                'Could not connect to PDO: ' . $e->getMessage() . '. DSN: ' . $dsn,
                (int) $e->getCode(),
                $e
            );
        }

        $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

        return $this;
    }
95069
public function connect()
    {
        if ($this->isConnected()) {
            return;
        }

        try {
            $this->doConnect();

            if (! $this->isConnected()) {
                $this->disconnect();

                throw new TransportException('Failed to connect to server '.$this->getRemoteAddress()
                    .', cause: Connect timeout '.$this->getTimeout().' ms.', 11);
            }

            Log::channel('homer')->info('Connect to server '.$this->getRemoteAddress().' from '.class_basename($this));
        } catch (TransportException $e) {
            $this->disconnect();

            Log::channel('homer')->warning($e->getMessage(), [
                'exception' => $e
            ]);

            throw $e;
        } catch (Throwable $e) {
            $this->disconnect();

            Log::channel('homer')->warning('Failed to connect to server '.$this->getRemoteAddress(), [
                'exception' => $e
            ]);

            throw new TransportException('Failed to connect to server '.$this->getRemoteAddress().', cause: '
                .$e->getMessage(), 0, $e);
        }
    }
824907
def connection
      @connect ||= Faraday.new do |f|
        f.adapter :net_http
        f.headers = connection_headers
        f.url_prefix = "#{default_url_prefix}/api/v#{api_version}/"
        f.response :json, content_type: /\bjson$/
      end
    end
593283
@Override
    protected Moment doConnect() throws IOException, ParseException {

        final NetTimeConfiguration cfg = this.getNetTimeConfiguration();

        URL url = new URL(cfg.getTimeServerAddress());
        int timeoutMillis =
            MathUtils.safeMultiply(cfg.getConnectionTimeout(), 1000);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setConnectTimeout(timeoutMillis);
        conn.setReadTimeout(timeoutMillis);
        conn.setUseCaches(false);
        conn.setRequestMethod("HEAD");

        int responseCode = conn.getResponseCode();

        if (responseCode >= 200 && responseCode <= 399) {
            return JAVA_UTIL_DATE.translate(new Date(conn.getDate()));
        }

        throw new IOException("HTTP server status: " + responseCode);

    }
714479
private function parseExceptionForErrorMessages(Exception $e)
    {
        if (! $e instanceof BadResponseException) {
            throw new ApiException($e->getMessage());
        }

        $response = $e->getResponse();
        Psr7\rewind_body($response);
        $responseBody = $response->getBody()->getContents();
        $decodedResponseBody = json_decode($responseBody, true);

        if (! is_null($decodedResponseBody) && isset($decodedResponseBody['error']['message']['value'])) {
            $errorMessage = $decodedResponseBody['error']['message']['value'];
        } else {
            $errorMessage = $responseBody;
        }

        throw new ApiException('Error ' . $response->getStatusCode() . ': ' . $errorMessage, $response->getStatusCode());
    }
743986
public function connect()
    {
        $streamContext = stream_context_create(array(
            $this->getTransport() => $this->getContextOptions()
        ));

        $streamResource = stream_socket_client(
            $this->getAddress(),
            $errorCode,
            $errorMessage,
            $this->getSocketTimeout(),
            $this->getConnectionFlags(),
            $streamContext
        );

        if (!$streamResource) {
            throw new \RuntimeException(sprintf(
                'Unable to connect on socket. Error [%d]: %s',
                $errorCode,
                $errorMessage
            ));
        }

        stream_set_blocking($streamResource, $this->isBlockingMode());

        $this->setStreamResource($streamResource);

        return $this;
    }
538214
protected function openConnection()
    {
        $this->response = null;
        $this->httpStatus = null;

        if (!$this->connection = curl_init()) {
            throw new ConnectionErrorException('Unable to open connection');
        }

        $this->setConnectionOptions($this->connectionOptions);
        return $this;
    }
757702
public function connect()
	{
		$request  = $this->sendRequest($this->baseUrl."/auth", array('username' => $this->login, 'password' => $this->password), 2);

		$response = json_decode($request['body'], true);
		if (array_key_exists('error', $response))
		{
			throw new \Exception('Erreur '.$response['code'].' : '.$response['error']);
		} else {
			$this->token = $response['token'];
			$this->saveToken();
		}
	}
1252891
public function connect() {
		if (! isset ( $this->apiTokens )) {
			$this->apiTokens = $this->_loadApiTokens ();
		}
		$token = $this->apiTokens->addToken ();
		$this->_addHeaderToken ( $token );
		return [ "access_token" => $token,"token_type" => "Bearer","expires_in" => $this->apiTokens->getDuration () ];
	}
1358985
private function connect() {
        $connection = fsockopen('tcp://'.$this->options['host'],
                                         $this->options['port'],
                                         $errorCode,
                                         $errorMsg,
                                         $this->options['timeout']);
        // TODO: connect() might hang without producing an error if the connection fails
        if (!$connection) throw new RuntimeException('Could not open socket: '.$errorMsg.' (error '.$errorCode.')');

        $data = stream_get_meta_data($connection);
        if ($data['timed_out']) throw new InfrastructureException('Timeout on socket connection');

        socket_set_timeout($connection, $this->options['timeout']);
        $this->connection = $connection;

        // init connection
        $this->readResponse();                          // read greeting
        $this->writeData('EHLO '.$this->hostName);      // extended "Hello" first
        $response = $this->readResponse();

        $this->parseResponse($response);
        if ($this->responseStatus != 250) {
            $this->writeData('HELO '.$this->hostName);  // regular "Hello" if the extended one fails
            $response = $this->readResponse();

            $this->parseResponse($response);
            if ($this->responseStatus != 250)
                throw new RuntimeException('HELO command not accepted: '.$this->responseStatus.' '.$this->response);
        }
    }
848040
public function connect()
    {
        $connectTimeout = 1;
        $errstr = '';
        $errno = 0;
        $stream = @stream_socket_client($this->nodeUrl, $errno, $errstr, $connectTimeout);

        if (!$stream) {
            $this->log->warning('unable to connect to '.$this->nodeUrl.': '.$errstr);
            throw new ConnectException('Unable to connect to resource '.$this->nodeUrl.'. '.$errstr, $errno);
        }

        $this->log->info('connected to '.$this->nodeUrl);
        $this->stream = $stream;

        return true;
    }
471902
public function callAction()
    {
        $request    = $this->getRequest();
        $response   = $this->getResponse();
        $formatName = $this->params()
                           ->fromRoute( 'format', 'json' );

        try
        {
            try
            {
                $format = $this->getServiceLocator()
                               ->get( 'Grid\\Core\\Model\\Rpc\\' .
                                      ucfirst( $formatName ) );
            }
            catch ( ServiceNotFoundException $ex )
            {
                throw new DomainException(
                    'The rpc-format (' . $formatName . ') not understood', 0, $ex
                );
            }

            if ( ! $format || ! $format instanceof RpcAbstract )
            {
                throw new DomainException(
                    'The rpc-format (' . $formatName . ') not understood'
                );
            }
        }
        catch ( DomainException $ex )
        {
            $this->logException( $ex, Logger::WARN );
            $response->setStatusCode( 500 );

            if ( ini_get('display_errors') )
            {
                if ( $response instanceof HttpResponse )
                {
                    $response->getHeaders()
                             ->addHeaderLine(
                                    'Content-Type',
                                    'text/plain; charset=utf-8'
                                );
                }

                $response->setContent( (string) $ex );
            }

            return $response;
        }

        $error = $format->parse( $request, $response );

        if ( $error )
        {
            try
            {
                throw new RpcException\BadMethodCallException(
                    'Parse error',
                    $format->errorCodes[ $error ]
                );
            }
            catch ( RpcException\BadMethodCallException $ex )
            {
                $this->logException( $ex, Logger::WARN );
            }

            return $format->error(
                $error,
                $format->errorCodes[ $error ],
                $error
            );
        }

        @ list( $serviceName,
                $method ) = explode( '::', $format->getMethod(), 2 );

        if ( empty( $method ) )
        {
            $method = '__invoke';
        }

        try
        {
            $service = $this->getServiceLocator()
                            ->get( $serviceName );
        }
        catch ( ServiceNotFoundException $ex )
        {
            $this->logException( $ex, Logger::WARN );

            return $format->error(
                RpcAbstract::METHOD_NOT_FOUND . ': ' . $format->getMethod(),
                $format->errorCodes[RpcAbstract::METHOD_NOT_FOUND],
                array(
                    'service'   => $serviceName,
                    'exception' => self::rawException( $ex ),
                )
            );
        }

        if ( empty( $service ) || ! $service instanceof CallableInterface )
        {
            $this->logException( $ex, Logger::WARN );

            return $format->error(
                RpcAbstract::METHOD_NOT_FOUND . ': ' . $format->getMethod(),
                $format->errorCodes[RpcAbstract::METHOD_NOT_FOUND],
                array(
                    'service'   => $serviceName,
                )
            );
        }
        else
        {
            try
            {
                ErrorHandler::start( E_ALL );
                $result = $service->call( $method, $format->getParams() );
                ErrorHandler::stop( true );
                return $format->response( $result );
            }
            catch ( RpcException\BadMethodCallException $ex )
            {
                ErrorHandler::stop( false );
                $this->logException( $ex, Logger::WARN );

                return $format->error(
                    RpcAbstract::METHOD_NOT_FOUND . ': ' . $format->getMethod(),
                    $format->errorCodes[RpcAbstract::METHOD_NOT_FOUND],
                    array(
                        'service'   => $serviceName,
                        'method'    => $method,
                        'exception' => self::rawException( $ex ),
                    )
                );
            }
            catch ( RpcException\InvalidArgumentException $ex )
            {
                ErrorHandler::stop( false );
                $this->logException( $ex, Logger::WARN );

                return $format->error(
                    $ex->getMessage(),
                    $format->errorCodes[RpcAbstract::INVALID_PARAMS],
                    self::rawException( $ex )
                );
            }
            catch ( Exception $ex )
            {
                ErrorHandler::stop( false );
                $this->logException( $ex );

                return $format->error(
                    RpcAbstract::INTERNAL . ': #' .
                        $ex->getCode() . ' - ' . $ex->getMessage(),
                    $format->errorCodes[RpcAbstract::INTERNAL],
                    self::rawException( $ex )
                );
            }
        }
    }
631404
public function connect()
    {
        $deferred = new Promise\Deferred();

        // Request a real-time connection...
        $this->apiCall('rtm.start')

        // then connect to the socket...
        ->then(function (Payload $response) {
            $responseData = $response->getData();
            // get the team info
            $this->team = new Team($this, $responseData['team']);

            // Populate self user.
            $this->users[$responseData['self']['id']] = new User($this, $responseData['self']);

            // populate list of users
            foreach ($responseData['users'] as $data) {
                $this->users[$data['id']] = new User($this, $data);
            }

            // populate list of channels
            foreach ($responseData['channels'] as $data) {
                $this->channels[$data['id']] = new Channel($this, $data);
            }

            // populate list of groups
            foreach ($responseData['groups'] as $data) {
                $this->groups[$data['id']] = new Group($this, $data);
            }

            // populate list of dms
            foreach ($responseData['ims'] as $data) {
                $this->dms[$data['id']] = new DirectMessageChannel($this, $data);
            }

            // populate list of bots
            foreach ($responseData['bots'] as $data) {
                $this->bots[$data['id']] = new Bot($this, $data);
            }

            // Log PHPWS things to stderr
            $logger = new \Zend\Log\Logger();
            $logger->addWriter(new \Zend\Log\Writer\Stream('php://stderr'));

            // initiate the websocket connection
            $this->websocket = new WebSocket($responseData['url'], $this->loop, $logger);
            $this->websocket->on('message', function ($message) {
                $this->onMessage($message);
            });

            return $this->websocket->open();
        }, function($exception) use ($deferred) {
            // if connection was not succesfull
            $deferred->reject(new ConnectionException(
                'Could not connect to Slack API: '. $exception->getMessage(),
                $exception->getCode()
            ));
        })

        // then wait for the connection to be ready.
        ->then(function () use ($deferred) {
            $this->once('hello', function () use ($deferred) {
                $deferred->resolve();
            });

            $this->once('error', function ($data) use ($deferred) {
                $deferred->reject(new ConnectionException(
                    'Could not connect to WebSocket: '.$data['error']['msg'],
                    $data['error']['code']));
            });
        });

        return $deferred->promise();
    }