22 require_once
'HTTP/Request2/SocketWrapper.php';
52 $address,
$timeout = 10, array $contextOptions = array(),
53 $username = null, $password = null
55 parent::__construct($address,
$timeout, $contextOptions);
57 if (strlen($username)) {
58 $request = pack(
'C4', 5, 2, 0, 2);
60 $request = pack(
'C3', 5, 1, 0);
62 $this->
write($request);
66 'Invalid version received from SOCKS5 proxy: ' .
$response[
'version'],
77 "Connection rejected by proxy due to unsupported auth method"
94 $request = pack(
'C2', 1, strlen($username)) . $username
95 . pack(
'C', strlen($password)) . $password;
97 $this->
write($request);
101 'Connection rejected by proxy due to invalid username and/or password'
115 public function connect($remoteHost, $remotePort)
117 $request = pack(
'C5', 0x05, 0x01, 0x00, 0x03, strlen($remoteHost))
118 . $remoteHost . pack(
'n', $remotePort);
120 $this->
write($request);
121 $response = unpack(
'Cversion/Creply/Creserved', $this->
read(1024));
124 'Invalid response received from SOCKS5 proxy',
129 "Unable to connect to {$remoteHost}:{$remotePort} through SOCKS5 proxy",