|
3 | 3 | // A simple example which requests https://www.google.com/ through a SOCKS proxy with local DNS resolution. |
4 | 4 | // The proxy can be given as first argument and defaults to localhost:1080 otherwise. |
5 | 5 | // |
6 | | -// Not already running a SOCKS proxy server? See also example #21 or try this: |
| 6 | +// Not already running a SOCKS proxy server? See also example #21 or try this: |
7 | 7 | // $ ssh -D 1080 localhost |
8 | 8 | // |
9 | 9 | // For illustration purposes only. If you want to send HTTP requests in a real |
10 | 10 | // world project, take a look at example #01, example #02 and https://github.com/reactphp/http#client-usage. |
11 | 11 |
|
12 | 12 | require __DIR__ . '/../vendor/autoload.php'; |
13 | 13 |
|
14 | | -$proxy = isset($argv[1]) ? $argv[1] : '127.0.0.1:1080'; |
| 14 | +$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:1080'; |
15 | 15 |
|
16 | 16 | $loop = React\EventLoop\Factory::create(); |
17 | 17 |
|
18 | 18 | // set up DNS server to use (Google's public DNS) |
19 | | -$client = new Clue\React\Socks\Client($proxy, new React\Socket\Connector($loop)); |
| 19 | +$proxy = new Clue\React\Socks\Client( |
| 20 | + $url, |
| 21 | + new React\Socket\Connector($loop) |
| 22 | +); |
20 | 23 | $connector = new React\Socket\Connector($loop, array( |
21 | | - 'tcp' => $client, |
| 24 | + 'tcp' => $proxy, |
22 | 25 | 'timeout' => 3.0, |
23 | 26 | 'dns' => '8.8.8.8' |
24 | 27 | )); |
25 | 28 |
|
26 | 29 | echo 'Demo SOCKS client connecting to SOCKS server ' . $proxy . PHP_EOL; |
27 | 30 |
|
28 | | -$connector->connect('tls://www.google.com:443')->then(function (React\Socket\ConnectionInterface $stream) { |
| 31 | +$connector->connect('tls://www.google.com:443')->then(function (React\Socket\ConnectionInterface $connection) { |
29 | 32 | echo 'connected' . PHP_EOL; |
30 | | - $stream->write("GET / HTTP/1.0\r\n\r\n"); |
31 | | - $stream->on('data', function ($data) { |
| 33 | + $connection->write("GET / HTTP/1.0\r\n\r\n"); |
| 34 | + $connection->on('data', function ($data) { |
32 | 35 | echo $data; |
33 | 36 | }); |
34 | 37 | }, function (Exception $e) { |
|
0 commit comments