Connects to a remote server.

@throws TeamSpeak3_Transport_Exception
@return void
777851
public function connect()
  {
    if($this->stream !== null) return;

    $host     = strval($this->config["host"]);
    $port     = strval($this->config["port"]);
    $timeout  = intval($this->config["timeout"]);
    $blocking = intval($this->config["blocking"]);

    if(empty($this->config["ssh"]))
    {
      $address = "tcp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
      $options = empty($this->config["tls"]) ? array() : array("ssl" => array("allow_self_signed" => TRUE, "verify_peer" => FALSE, "verify_peer_name" => FALSE));

      $this->stream = @stream_socket_client($address, $errno, $errstr, $this->config["timeout"], STREAM_CLIENT_CONNECT, stream_context_create($options));

      if($this->stream === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception(TeamSpeak3_Helper_String::factory($errstr)->toUtf8()->toString(), $errno);
      }

      if(!empty($this->config["tls"]))
      {
        stream_socket_enable_crypto($this->stream, TRUE, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
      }
    }
    else
    {
      $this->session = @ssh2_connect($host, $port);

      if($this->session === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception("failed to establish secure shell connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "'");
      }

      if(!@ssh2_auth_password($this->session, $this->config["username"], $this->config["password"]))
      {
        throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid loginname or password", 0x208);
      }

      $this->stream = @ssh2_shell($this->session, "raw");

      if($this->stream === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception("failed to open a secure shell on server '" . $this->config["host"] . ":" . $this->config["port"] . "'");
      }
    }

    @stream_set_timeout($this->stream, $timeout);
    @stream_set_blocking($this->stream, $blocking ? 1 : 0);
  }
1056112
public function startAction()
  {
    $this->setNoRender();

    /* grab user parameters from $_REQUEST array */
    $sid = TeamSpeak3_Helper_Uri::getUserParam("id", 0);

    try
    {
      /* start server */
      $this->ts3->serverStart($sid);

      /* save custom ok mesage */
      $this->setLastEvent("The virtual server (ID " . $sid . ") has been started.");
    }
    catch(Exception $e)
    {
      /* save catched error mesage */
      $this->setLastEvent($e->getMessage(), TRUE);
    }

    /* goto indexAction() */
    $this->redirect("server");
  }
1002229
public function connect()
    {
        if ($this->_status !== self::STATUS_INITIAL && $this->_status !== self::STATUS_CLOSING &&
             $this->_status !== self::STATUS_CLOSED) {
            return;
        }
        $this->_status           = self::STATUS_CONNECTING;
        $this->_connectStartTime = microtime(true);
        // Open socket connection asynchronously.
        if ($this->_contextOption) {
            $context = stream_context_create($this->_contextOption);
            $this->_socket = stream_socket_client("{$this->transport}://{$this->_remoteAddress}", $errno, $errstr, 0,
                STREAM_CLIENT_ASYNC_CONNECT, $context);
        } else {
            $this->_socket = stream_socket_client("{$this->transport}://{$this->_remoteAddress}", $errno, $errstr, 0,
                STREAM_CLIENT_ASYNC_CONNECT);
        }
        // If failed attempt to emit onError callback.
        if (!$this->_socket) {
            $this->emitError(WORKERMAN_CONNECT_FAIL, $errstr);
            if ($this->_status === self::STATUS_CLOSING) {
                $this->destroy();
            }
            if ($this->_status === self::STATUS_CLOSED) {
                $this->onConnect = null;
            }
            return;
        }
        // Add socket to global event loop waiting connection is successfully established or faild. 
        Worker::$globalEvent->add($this->_socket, EventInterface::EV_WRITE, array($this, 'checkConnection'));
        // For windows.
        if(DIRECTORY_SEPARATOR === '\\') {
            Worker::$globalEvent->add($this->_socket, EventInterface::EV_EXCEPT, array($this, 'checkConnection'));
        }
    }
267248
protected function _connect()
    {
        if (!is_null($this->_connection)) {
            return;
        }

        try {
            $this->_connection = new Horde_Imap_Client_Socket_Connection_Socket(
                $this->getParam('hostspec'),
                $this->getParam('port'),
                $this->getParam('timeout'),
                $this->getParam('secure'),
                $this->getParam('context'),
                array(
                    'debug' => $this->_debug,
                    'debugliteral' => $this->getParam('debug_literal')
                )
            );
        } catch (Horde\Socket\Client\Exception $e) {
            $e2 = new Horde_Imap_Client_Exception(
                Horde_Imap_Client_Translation::r("Error connecting to mail server."),
                Horde_Imap_Client_Exception::SERVER_CONNECT
            );
            $e2->details = $e->details;
            throw $e2;
        }

        // If we already have capability information, don't re-set with
        // (possibly) limited information sent in the initial banner.
        if (isset($this->_init['capability'])) {
            $this->_temp['no_cap'] = true;
        }

        /* Get greeting information (untagged response). */
        try {
            $this->_getLine($this->_pipeline());
        } catch (Horde_Imap_Client_Exception_ServerResponse $e) {
            if ($e->status === Horde_Imap_Client_Interaction_Server::BYE) {
                /* Server is explicitly rejecting our connection (RFC 3501
                 * [7.1.5]). */
                $e->setMessage(Horde_Imap_Client_Translation::r("Server rejected connection."));
                $e->setCode(Horde_Imap_Client_Exception::SERVER_CONNECT);
            }
            throw $e;
        }

        // Check for IMAP4rev1 support
        if (!$this->_capability('IMAP4REV1')) {
            throw new Horde_Imap_Client_Exception(
                Horde_Imap_Client_Translation::r("The mail server does not support IMAP4rev1 (RFC 3501)."),
                Horde_Imap_Client_Exception::SERVER_CONNECT
            );
        }

        // Set language if NOT using imapproxy
        if (empty($this->_init['imapproxy'])) {
            if ($this->_capability('XIMAPPROXY')) {
                $this->_setInit('imapproxy', true);
            } else {
                $this->setLanguage();
            }
        }

        // If pre-authenticated, we need to do all login tasks now.
        if (!empty($this->_temp['preauth'])) {
            $this->login();
        }
    }
1352927
public function connect()
	{
		if($this->_ssl_mode === true)
		{
			if( ! function_exists('ftp_ssl_connect'))
			{
				throw new \RuntimeException('ftp_ssl_connect() function is missing.');
			}

			$this->_conn_id = @ftp_ssl_connect($this->_hostname, $this->_port, $this->_timeout);
		}

		else
		{
			$this->_conn_id = @ftp_connect($this->_hostname, $this->_port, $this->_timeout);
		}

		if ($this->_conn_id === false)
		{
			if ($this->_debug == true)
			{
				throw new \FtpConnectionException('Unable to establish a connection');
			}
			return false;
		}

		if ( ! $this->_login())
		{
			if ($this->_debug == true)
			{
				throw new \FtpConnectionException('Unable to login');
			}
		}

		// Set passive mode if needed
		if ($this->_passive == true)
		{
			ftp_pasv($this->_conn_id, true);
		}

		return $this;
	}
167002
public function connect()
    {
        try {
            // Instantiate an S3 client
            $this->setS3Client(new S3Client([
                        'version' => $this->supplier['version'],
                        'region' => $this->supplier['region'],
                        'http'    => $this->supplier['http']
                    ]
                )
            );
        } catch (\Exception $e) {
            return false;
        }

        return true;
    }
1281265
public function connect()
	{
		//Attempt to connect to host
		$link = ssh2_connect($this->_config['host'], $this->_config['port']);
		
		//If host connection fails, throw exception
		if(!$link)
		{
			throw new \Exception('Unable to connect to '.$host.' on port '.$port);
		}
		else
		{
			//Assign the connection link to the class property
			$this->_conn_link = $link;
			
			//If host fingerprint is not NULL, attempt to verify fingerprint
			if(!is_null($this->_config['host_fingerprint'])) 
			{
				$verify = $this->verify_host_fingerprint();
				
				//If the fingerprint is not verified, throw exception
				if(!$verify)
				{
					throw new \Exception('Unable to verify host fingerprint');
				}
			}
		}
		
		//Attempt to login user
		if($this->_config['authentication_method'] == 'KEY')
		{
			$this->_connected = $this->login_key();
		}
		else
		{
			$this->_connected = $this->login_password();
		}

		$this->_connected && $this->_sftp = ssh2_sftp($link);
	}
28381
protected function connect()
    {
        if (!empty($this->conn)) {
            return;
        }

        if (!extension_loaded('ftp')) {
            throw new ServerException(
                "Unable to initialize ftp storage server, extension 'ftp' not found"
            );
        }

        $conn = ftp_connect(
            $this->options['host'],
            $this->options['port'],
            $this->options['timeout']
        );

        if (empty($conn)) {
            throw new ServerException(
                "Unable to connect to remote FTP server '{$this->options['host']}'"
            );
        }

        if (!ftp_login($conn, $this->options['username'], $this->options['password'])) {
            throw new ServerException(
                "Unable to authorize on remote FTP server '{$this->options['host']}'"
            );
        }

        if (!ftp_pasv($conn, $this->options['passive'])) {
            throw new ServerException(
                "Unable to set passive mode at remote FTP server '{$this->options['host']}'"
            );
        }

        $this->conn = $conn;
    }
1238772
private function connecting() : void
    {
        $this->connected = false;
        $this->closing
            ? $this->closed()->resolve()
            : $this->client = Socket::connect($this->endpoint, $this->events)
        ;
    }
404735
public void connect() throws IOException {
        if (isConnected() && tree.session.transport.tconHostName == null) {
            /* Tree thinks it is connected but transport disconnected
             * under it, reset tree to reflect the truth.
             */
            tree.treeDisconnect(true);
        }

        if( isConnected() ) {
            return;
        }

        getUncPath0();
        getFirstAddress();
        for ( ;; ) {
            try {
                doConnect();
                return;
            } catch(SmbAuthException sae) {
                throw sae; // Prevents account lockout on servers with multiple IPs
            } catch(SmbException se) {
                if (getNextAddress() == null) 
                    throw se;
                if (log.level >= 3)
                    se.printStackTrace(log);
            }
        }
    }
837226
public function connect()
    {
        list($host, $port) = explode(':', $this->getServer());
        if ($this->stream->open($host, $port, $this->getTimeout()) === false) {
            throw new Exception(sprintf('Cannot connect to server %s', $this->getServer()), Exception::SERVER_OFFLINE);
        }

        return true;
    }
777778
public function connect(): bool
    {
        if ($this->isConnected()) {
            return true;
        }

        $errno = null;
        $errstr = null;

        // Supress PHP error, we're handling it
        $this->socket = @stream_socket_client(
            $this->getUri(),
            $errno,
            $errstr,
            $this->options['timeout_connect'],
            STREAM_CLIENT_CONNECT,
            $this->getStreamContext()
        );

        if (!$this->socket) {
            throw new \Wrench\Exception\ConnectionException(sprintf(
                'Could not connect to socket: %s (%d)',
                $errstr,
                $errno
            ));
        }

        stream_set_timeout($this->socket, $this->options['timeout_socket']);

        return ($this->connected = true);
    }
1156
public function syn()
  {
    if(!isset($this->options["host"]) || empty($this->options["host"])) $this->options["host"] = $this->default_host;
    if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port;

    $this->initTransport($this->options, "TeamSpeak3_Transport_UDP");
    $this->transport->setAdapter($this);

    TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));

    $this->getTransport()->send(TeamSpeak3_Helper_String::fromHex(33));

    if(!preg_match_all("/,?(\d+)#([0-9a-zA-Z\._-]+),?/", $this->getTransport()->read(96), $matches) || !isset($matches[1]) || !isset($matches[2]))
    {
      throw new TeamSpeak3_Adapter_Update_Exception("invalid reply from the server");
    }

    $this->build_datetimes = $matches[1];
    $this->version_strings = $matches[2];

    TeamSpeak3_Helper_Signal::getInstance()->emit("updateConnected", $this);
  }
230176
public function open()
    {
        $ok = @socket_connect($this->socket, $this->host, $this->port);
        if ($ok === false) {
            throw new TTransportException('socket_connect failed');
        }
    }
570776
protected function connect()
    {
        if (!is_object(self::$instance)) {
            self::$instance = new \Memcache();

            // Cluster connections
            $hosts = explode(',', $this->options['host']);
            $ports = explode(',', $this->options['port']);
            if (empty($ports[0])) {
                $ports[0] = 11211;
            }

            // connection establishment
            foreach ((array) $hosts as $i => $host) {
                $port = isset($ports[$i]) ? $ports[$i] : $ports[0];
                $this->options['timeout'] > 0 ?
                    self::$instance->addServer($host, $port, $this->options['persistent'], 1, $this->options['timeout']) :
                    self::$instance->addServer($host, $port, $this->options['persistent'], 1);
            }
        }
    }
251163
protected function connect()
    {
        $schema = ($this->_secure === 'ssl' || $this->_secure === 'tls' ? $this->_secure . '://' : '');
        $url = $schema  . $this->_host . ':' . $this->_port;
        $this->_connection = stream_socket_client($url, $errno, $error, $this->_timeout, STREAM_CLIENT_CONNECT, $this->_context);
        if (!$this->_connection) {
            throw new NetException($error, $errno);
        }
        stream_set_timeout($this->_connection, $this->_timeout, 0);
        $this->read();

        $this->write("EHLO {$this->_client}");
        $ehloResponse = $this->read();

        if ($this->_secure === 'starttls') {
            $this->write('STARTTLS', 220);
            if (!stream_socket_enable_crypto($this->_connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
                throw new NetException('Unable to connect via TLS.');
            }
            $this->write("EHLO {$this->_client}", 250);
        }

        if ($this->_username !== null && $this->_password !== null) {
            $authMechanisms = [];
            if (preg_match('~^250[ -]AUTH (.*)$~im', $ehloResponse, $matches)) {
                $authMechanisms = explode(' ', trim($matches[1]));
            }

            if (in_array('PLAIN', $authMechanisms, true)) {
                $credentials = $this->_username . "\0" . $this->_username . "\0" . $this->_password;
                $this->write('AUTH PLAIN ' . base64_encode($credentials), 235, 'PLAIN credentials');
            } else {
                $this->write('AUTH LOGIN', 334);
                $this->write(base64_encode($this->_username), 334, 'username');
                $this->write(base64_encode($this->_password), 235, 'password');
            }
        }
    }
476224
public function connect()
    {
        $logger = $this->getLogger();
        $monolog = $logger->driver();

        $monolog->pushHandler(new SocketHandler('tcp://127.0.0.1:8337'));

        try {
            $logger->info('Debug client connecting...');
        } catch (Exception $e) {
            $monolog->popHandler();

            return false;
        }

        return true;
    }