Return True if the connection to the host and port is successful.

        @return: bool
18953
def is_available(self):
        
        if self.scheme in NOOP_PROTOCOLS:
            return True

        if not self.port:
            raise RuntimeError('port is required')

        s = socket.socket()
        try:
            s.connect((self.host, self.port))
        except Exception:
            return False
        else:
            return True
595715
public function useAssociatedPort() : bool
   {

      if ( null === $this->port )
      {
         return true;
      }

      switch ( $this->scheme )
      {

         case UrlScheme::HTTP:
            return ( $this->port === 80 );

         case UrlScheme::SSL:
            return ( $this->port === 443 );

         case UrlScheme::FTP:
            return ( $this->port === 21 );

         default :
            return false;

      }

   }
470419
public function connect()
	{
		if ($this->host == '')
		{
			return false;
		}

		$this->resource = @ ldap_connect($this->host, $this->port);

		if ($this->resource)
		{
			if ($this->use_ldapV3)
			{
				if (!@ldap_set_option($this->resource, LDAP_OPT_PROTOCOL_VERSION, 3))
				{
					return false;
				}
			}

			if (!@ldap_set_option($this->resource, LDAP_OPT_REFERRALS, (int) $this->no_referrals))
			{
				return false;
			}

			if ($this->negotiate_tls)
			{
				if (!@ldap_start_tls($this->resource))
				{
					return false;
				}
			}

			return true;
		}
		else
		{
			return false;
		}
	}
764607
def is_server_running(host, port):
    
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        return s.connect_ex((host, port)) == 0
    finally:
        s.close()
1014840
public function connect()
        {
            // check if non-SSL connection
            if(!static::$ssl) {
                // attempt connection
                if(!static::$_stream = ftp_connect(static::$_host, static::$_port, static::$_timeout)) {
                    // set last error
                    static::$error = "Failed to connect to {static::$_host}";
                    return false;
                }
            // SSL connection
            } elseif(function_exists("ftp_ssl_connect")) {
                // attempt SSL connection
                if(!static::$_stream = ftp_ssl_connect(static::$_host, static::$_port, static::$_timeout)) {
                    // set last error
                    static::$error = "Failed to connect to {static::$_host} (SSL connection)";
                    return false;
                }
            // invalid connection type
            } else {
                static::$error = "Failed to connect to {static::$_host} (invalid connection type)";
                return false;
            }

            // attempt login
            if(ftp_login(static::$_stream, static::$_user, static::$_pwd)) {
                // set passive mode
                ftp_pasv(static::$_stream, (bool)static::$passive);

                // set system type
                static::$systemType = ftp_systype(static::$_stream);

                // connection successful
                return true;
            // login failed
            } else {
                static::$error = "Failed to connect to {static::$_host} (login failed)";
                return false;
            }
        }
496231
public function connect($host = '127.0.0.1', $port = 21)
	{
		$errno = null;
		$err   = null;

		// If already connected, return
		if (\is_resource($this->conn))
		{
			return true;
		}

		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			$this->conn = @ftp_connect($host, $port, $this->timeout);

			if ($this->conn === false)
			{
				throw new FilesystemException(sprintf('%1$s: Could not connect to host " %2$s " on port " %3$s "', __METHOD__, $host, $port));
			}

			// Set the timeout for this connection
			ftp_set_option($this->conn, FTP_TIMEOUT_SEC, $this->timeout);

			return true;
		}

		// Connect to the FTP server.
		$this->conn = @ fsockopen($host, $port, $errno, $err, $this->timeout);

		if (!$this->conn)
		{
			throw new FilesystemException(
				sprintf(
					'%1$s: Could not connect to host " %2$s " on port " %3$s ". Socket error number: %4$s and error message: %5$s',
					__METHOD__,
					$host,
					$port,
					$errno,
					$err
				)
			);
		}

		// Set the timeout for this connection
		socket_set_timeout($this->conn, $this->timeout, 0);

		// Check for welcome response code
		if (!$this->_verifyResponse(220))
		{
			throw new FilesystemException(sprintf('%1$s: Bad response. Server response: %2$s [Expected: 220]', __METHOD__, $this->response));
		}

		return true;
	}
1204065
def is_connectable(port, host="localhost"):
    
    socket_ = None
    try:
        socket_ = socket.create_connection((host, port), 1)
        result = True
    except _is_connectable_exceptions:
        result = False
    finally:
        if socket_:
            socket_.close()
    return result
1341940
public function isConnected(): bool
    {
        try{
            return false !== $this->instance->getAttribute(\PDO::ATTR_SERVER_INFO);
        } catch (\Throwable $e) {
        }
        return false;
    }
125878
public function tryConnect() {
		if ($this->db_connected) {
			return TRUE;
		}
		if (!class_exists('mysqli')) {
			BLog::addToLog($this->logsuffix . ': MySQLi class not found', LL_ERROR);
			return FALSE;
		}
		$this->mysqli = new \mysqli($this->db_host, $this->db_username, $this->db_password, $this->db_name, $this->db_port);
		if ((empty($this->mysqli)) || (mysqli_connect_errno())) {
			BLog::addToLog($this->logsuffix . ': ' . mysqli_connect_error(), LL_ERROR);
			return FALSE;
		}
		if (!$this->mysqli->set_charset("utf8")) return FALSE;
		$this->db_connected = TRUE;
		return TRUE;
	}
387566
public function isSuccessful()
    {
        $successful = false;

        $errorCode = $this->getErrorCode();
        if ($errorCode === 200 || $errorCode === 0) {
            $successful = true;
        }

        return $successful;
    }
956552
def open(self) -> bool:
        
        if self.connection:
            # Nothing to do if the connection is already open.
            return False

        connection_params = {'local_hostname': DNS_NAME.get_fqdn()}
        if self.timeout is not None:
            connection_params['timeout'] = self.timeout
        try:
            self.connection = smtplib.SMTP(self.host, self.port,
                                           **connection_params)

            # TLS
            context = ssl.SSLContext(self._protocol())
            if self.ssl_certfile:
                context.load_cert_chain(certfile=self.ssl_certfile,
                                        keyfile=self.ssl_keyfile)
            self.connection.ehlo()
            self.connection.starttls(context=context)
            self.connection.ehlo()
            if self.username and self.password:
                self.connection.login(self.username, self.password)
                log.debug("Successful SMTP connection/login")
            else:
                log.debug("Successful SMTP connection (without login)")
            return True
        except smtplib.SMTPException:
            log.debug("SMTP connection and/or login failed")
            if not self.fail_silently:
                raise
795440
public function isConnected()
    {
        try {
            return \is_resource($this->connection) && \ftp_rawlist($this->connection, $this->getRoot()) !== false;
        } catch (\ErrorException $e) {
            if (\strpos($e->getMessage(), 'ftp_rawlist') === false) {
                throw $e;
            }

            return false;
        }
    }
327842
public function getIsSecureConnection()
    {
        $https = $this->getServerParam('HTTPS');
        if ($https !== null && (strcasecmp($https, 'on') === 0 || $https == 1)) {
            return true;
        }
        foreach ($this->secureProtocolHeaders as $header => $values) {
            if ($this->hasHeader($header)) {
                foreach ($values as $value) {
                    if (strcasecmp($this->getHeaderLine($header), $value) === 0) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
224763
public function reconnect()
    {
        if ($this->getMaxReconnects() < $this->getReconnectCount()) {
            return false;
        }

        $this->increaseReconnectCount();
        // returns the state if the ping was possible
        return $this->ping();
    }
89410
public function connect(): bool
    {
        if ($this->isConnected()) {
            return true;
        }

        $this->socket = $this->createSocket();
        try {
            if (socket_connect($this->socket, $this->address, $this->port) === false) {
                throw new RelayException(socket_strerror(socket_last_error($this->socket)));
            }
        } catch (\Exception $e) {
            throw new RelayException("unable to establish connection {$this}", 0, $e);
        }

        return true;
    }
73207
public function isConnected()
    {
        return ((bool) (is_resource($this->_connection)
                    && (get_resource_type($this->_connection) == 'oci8 connection'
                     || get_resource_type($this->_connection) == 'oci8 persistent connection')));
    }
315057
public function connect(): bool
	{
		if ($this->ssl === true)
		{
			$this->connection = fsockopen('ssl://'.$this->host, $this->port);
		}
		else
		{
			$this->connection = fsockopen($this->host, $this->port);
		}

		return $this->connected();
	}