enable socks5 proxy
@param string $host
@param int $port
@param null|string $username
@param null|string $password
@return $this
162573
public function withSocks5(string $host, int $port, ?string $username, ?string $password): self
    {
        $this->proxy = [
            'socks5_host' => $host,
            'socks5_port' => $port,
            'socks5_username' => $username,
            'socks5_password' => $password,
        ];

        return $this;
    }
788754
public function login($username = null, $password = null)
    {
        $this->_username = null !== $username ? $username : $this->_username;
        $this->_password = null !== $password ? $password : $this->_password;

        if (null === $this->_ssh_resource) {
            throw new TransportException(sprintf('None SSH connection available.'));
        }

        if (null === $this->_ssh_key_pub) {
            if (false === ssh2_auth_password($this->_ssh_resource, $this->_username, $this->_password)) {
                throw new TransportException(sprintf('Could not authenticate with username %s.', $this->_username));
            }
        } else {
            if (false === ssh2_auth_pubkey_file($this->_ssh_resource, $this->_username, $this->_ssh_key_pub, $this->_ssh_key_priv, $this->_ssh_key_pass)) {
                throw new TransportException(sprintf('Could not authenticate with keyfile %s.', $this->_keyfile));
            }
        }

        if (false === $this->_sftp_resource = ssh2_sftp($this->_ssh_resource)) {
            throw new TransportException("Could not initialize SFTP subsystem.");
        }

        return $this;
    }
1373593
public function connectUdp($host, $port)
    {
        $this->type = 'udp';
        $pton = @inet_pton($host);
        if ($pton === false) { // dirty check
            \PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($host, function ($result) use ($host, $port) {
                if (!$result) {
                    Daemon::log(get_class($this) . '->connectUdp : unable to resolve hostname: ' . $host);
                    $this->onStateEv($this->bev, \EventBufferEvent::ERROR);
                    return;
                }
                // @todo stack of addrs
                if (is_array($result)) {
                    srand(Daemon::$process->getPid());
                    $real = $result[rand(0, sizeof($result) - 1)];
                    srand();
                } else {
                    $real = $result;
                }
                $this->connectUdp($real, $port);
            });
            return true;
        }
        $this->hostReal = $host;
        if ($this->host === null) {
            $this->host = $this->hostReal;
        }
        $l = mb_orig_strlen($pton);
        if ($l === 4) {
            $this->addr = $host . ':' . $port;
            /* @TODO: use EventUtil::SOCK_DGRAM */
            $fd = socket_create(\EventUtil::AF_INET, SOCK_DGRAM, \EventUtil::SOL_UDP);
        } elseif ($l === 16) {
            $this->addr = '[' . $host . ']:' . $port;
            $fd = socket_create(\EventUtil::AF_INET6, SOCK_DGRAM, \EventUtil::SOL_UDP);
        } else {
            return false;
        }
        if (!$fd) {
            return false;
        }
        socket_set_nonblock($fd);
        @socket_connect($fd, $host, $port);
        socket_getsockname($fd, $this->locAddr, $this->locPort);
        $this->setFd($fd);
        if (!$this->bev) {
            return false;
        }
        return true;
    }
723714
protected function checkConnection($host, $port)
    {
        $host = ($port == 443) ? 'ssl://' . $host : 'tcp://' . $host;

        // If the connection could not be established, fsockopen sadly does not
        // only return false (as documented), but also always issues a warning.
        if (($this->connection === null) &&
            (($this->connection = @stream_socket_client($host . ':' . $port, $errno, $errstr)) === false)) {
            // This is a bit hackisch...
            $this->connection = null;
            throw new \RuntimeException('fail');
        }
    }
631701
public function setPort($port)
    {
        if ($port != $this->_port) {
            $this->_port = (int)$port;
            $this->_hostInfo = null;
        }
        return $this;
    }
1060670
protected function createConnection($host, $port, $methods, $callbacks)
    {
        return @ssh2_connect($host, $port, $methods, $callbacks);
    }
1037846
private function createClient(
        string $host,
        int $httpPort,
        int $udpPort,
        string $user,
        string $password,
        bool $udp = false,
        bool $ssl = false,
        bool $sslVerify = false,
        float $timeout = 0.0,
        float $connectTimeout = 0.0
    ): Client {
        $client = new Client($host, $httpPort, $user, $password, $ssl, $sslVerify, $timeout, $connectTimeout);

        if ($udp) {
            $client->setDriver(new UDP($client->getHost(), $udpPort));
        }

        return $client;
    }
881844
public function setHost($host)
    {
        if (strpos($host, ':') === false) {
            $this->host = $host;
        } else {
            list($host, $port) = explode(':', $host);
            $this->host = $host;
            $this->setPort($port);
        }

        return $this;
    }
729635
public function setProxy($host = null, $port = null)
    {
        if (!$host) {
            $this->proxyHost = null;
            $this->proxyPort = null;
            return;
        }

        if (!is_string($host)) {
            throw new InvalidArgumentException('host expects a string, ' . gettype($host) . ' given.');
        }

        if (!is_int($port)) {
            throw new InvalidArgumentException('port expects an integer, ' . gettype($port) . ' given.');
        }

        $this->proxyHost = $host;
        $this->proxyPort = $port;
    }
698128
public function connect($host, $port = 80, $secure = false)
    {
        // If no proxy is set, fall back to Socket adapter
        if (! $this->config['proxy_host']) return parent::connect($host, $port, $secure);

        // Go through a proxy - the connection is actually to the proxy server
        $host = $this->config['proxy_host'];
        $port = $this->config['proxy_port'];

        // If we are connected to the wrong proxy, disconnect first
        if (($this->connected_to[0] != $host || $this->connected_to[1] != $port)) {
            if (is_resource($this->socket)) $this->close();
        }

        // Now, if we are not connected, connect
        if (! is_resource($this->socket) || ! $this->config['keepalive']) {
            $this->socket = @fsockopen($host, $port, $errno, $errstr, (int) $this->config['timeout']);
            if (! $this->socket) {
                $this->close();
                require_once 'Zend/Http/Client/Adapter/Exception.php';
                throw new Zend_Http_Client_Adapter_Exception(
                    'Unable to Connect to proxy server ' . $host . ':' . $port . '. Error #' . $errno . ': ' . $errstr);
            }

            // Set the stream timeout
            if (!stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
                require_once 'Zend/Http/Client/Adapter/Exception.php';
                throw new Zend_Http_Client_Adapter_Exception('Unable to set the connection timeout');
            }

            // Update connected_to
            $this->connected_to = array($host, $port);
        }
    }
666540
public Proxy setSocksPassword(String password) {
    verifyProxyTypeCompatibility(ProxyType.MANUAL);
    this.proxyType = ProxyType.MANUAL;
    this.socksPassword = password;
    return this;
  }
969347
def enable_proxy(self, host, port):
        """"""

        self.proxy = [host, _number(port)]
        self.proxy_enabled = True
1027451
public static function create($host, $port)
  {
    $transceiver = new SocketTransceiver();
    $transceiver->createSocket($host, $port);
    
    return $transceiver;
  }
1223122
public function setHTTPProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '')
    {
        $this->proxyhost = $proxyhost;
        $this->proxyport = $proxyport;
        $this->proxyusername = $proxyusername;
        $this->proxypassword = $proxypassword;
    }
33272
public static function create($host, $port, $password)
    {
        $factory = new \Socket\Raw\Factory();
        $socket = $factory->createClient(sprintf('%s:%s', $host, $port));

        return new \gries\Rcon\Connection($socket, $password);
    }
472511
public function createClient($host, $port)
    {
        return $this->connector->create($host, $port)->then(function (DuplexStreamInterface $stream) {
            return new Client($stream);
        });
    }
802113
public static function useSocks5($host, $port = 1080, $user = null, $pass = null)
    {
        if ($host === null) {
            self::$_socks5 = [];
        } else {
            self::$_socks5 = ['conn' => 'tcp://' . $host . ':' . $port];
            if ($user !== null && $pass !== null) {
                self::$_socks5['user'] = $user;
                self::$_socks5['pass'] = $pass;
            }
        }
    }