@@ -84,9 +84,9 @@ to google.com via a local SOCKS proxy server:
8484``` php
8585$loop = React\EventLoop\Factory::create();
8686$connector = new React\Socket\Connector($loop);
87- $client = new Clue\React\Socks\Client('127.0.0.1:1080', $connector);
87+ $proxy = new Clue\React\Socks\Client('127.0.0.1:1080', $connector);
8888
89- $client ->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
89+ $proxy ->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
9090 $connection->write("GET / HTTP/1.0\r\n\r\n");
9191
9292 $connection->on('data', function ($chunk) {
@@ -130,13 +130,13 @@ like this:
130130
131131``` php
132132$connector = new React\Socket\Connector($loop);
133- $client = new Clue\React\Socks\Client('127.0.0.1:1080', $connector);
133+ $proxy = new Clue\React\Socks\Client('127.0.0.1:1080', $connector);
134134```
135135
136136You can omit the port if you're using the default SOCKS port 1080:
137137
138138``` php
139- $client = new Clue\React\Socks\Client('127.0.0.1', $connector);
139+ $proxy = new Clue\React\Socks\Client('127.0.0.1', $connector);
140140```
141141
142142If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
@@ -151,7 +151,7 @@ $connector = new React\Socket\Connector($loop, array(
151151 )
152152));
153153
154- $client = new Clue\React\Socks\Client('my-socks-server.local:1080', $connector);
154+ $proxy = new Clue\React\Socks\Client('my-socks-server.local:1080', $connector);
155155```
156156
157157This is one of the two main classes in this package.
@@ -169,9 +169,9 @@ This makes it fairly simple to add SOCKS proxy support to pretty much any
169169higher-level component:
170170
171171``` diff
172- - $client = new SomeClient ($connector);
172+ - $acme = new AcmeApi ($connector);
173173+ $proxy = new Clue\React\Socks\Client('127.0.0.1:1080', $connector);
174- + $client = new SomeClient ($proxy);
174+ + $acme = new AcmeApi ($proxy);
175175```
176176
177177#### Plain TCP connections
@@ -183,7 +183,12 @@ As documented above, you can simply invoke its `connect()` method to establish
183183a streaming plain TCP/IP connection and use any higher level protocol like so:
184184
185185``` php
186- $client->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
186+ $proxy = new Clue\React\Socks\Client(
187+ '127.0.0.1:1080',
188+ new React\Socket\Connector($loop)
189+ );
190+
191+ $proxy->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
187192 echo 'connected to www.google.com:80';
188193 $connection->write("GET / HTTP/1.0\r\n\r\n");
189194
@@ -197,8 +202,13 @@ You can either use the `Client` directly or you may want to wrap this connector
197202in ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) :
198203
199204``` php
205+ $proxy = new Clue\React\Socks\Client(
206+ '127.0.0.1:1080',
207+ new React\Socket\Connector($loop)
208+ );
209+
200210$connector = new React\Socket\Connector($loop, array(
201- 'tcp' => $client ,
211+ 'tcp' => $proxy ,
202212 'dns' => false
203213));
204214
@@ -238,8 +248,13 @@ ReactPHP's [`Connector`](https://github.com/reactphp/socket#connector) or the
238248low-level [ ` SecureConnector ` ] ( https://github.com/reactphp/socket#secureconnector ) :
239249
240250``` php
251+ $proxy = new Clue\React\Socks\Client(
252+ '127.0.0.1:1080',
253+ new React\Socket\Connector($loop)
254+ );
255+
241256$connector = new React\Socket\Connector($loop, array(
242- 'tcp' => $client ,
257+ 'tcp' => $proxy ,
243258 'dns' => false
244259));
245260
@@ -274,7 +289,7 @@ to the constructor like this:
274289
275290``` php
276291$connector = new React\Socket\Connector($loop, array(
277- 'tcp' => $client ,
292+ 'tcp' => $proxy ,
278293 'tls' => array(
279294 'verify_peer' => false,
280295 'verify_peer_name' => false
@@ -294,7 +309,7 @@ This allows you to send both plain HTTP and TLS-encrypted HTTPS requests like th
294309
295310``` php
296311$proxy = new Clue\React\Socks\Client(
297- 'socks:// 127.0.0.1:1080',
312+ '127.0.0.1:1080',
298313 new React\Socket\Connector($loop)
299314);
300315
@@ -391,16 +406,16 @@ URI scheme acts as an alias for the default `socks://` URI scheme.
391406
392407``` php
393408// all three forms are equivalent
394- $client = new Clue\React\Socks\Client('127.0.0.1', $connector);
395- $client = new Clue\React\Socks\Client('socks://127.0.0.1', $connector);
396- $client = new Clue\React\Socks\Client('socks5://127.0.0.1', $connector);
409+ $proxy = new Clue\React\Socks\Client('127.0.0.1', $connector);
410+ $proxy = new Clue\React\Socks\Client('socks://127.0.0.1', $connector);
411+ $proxy = new Clue\React\Socks\Client('socks5://127.0.0.1', $connector);
397412```
398413
399414If want to explicitly set the protocol version to SOCKS4(a), you can use the URI
400415scheme ` socks4:// ` as part of the SOCKS URI:
401416
402417``` php
403- $client = new Clue\React\Socks\Client('socks4://127.0.0.1', $connector);
418+ $proxy = new Clue\React\Socks\Client('socks4://127.0.0.1', $connector);
404419```
405420
406421#### DNS resolution
@@ -429,11 +444,16 @@ However, wrapping the `Client` in ReactPHP's
429444[ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) actually
430445performs local DNS resolution unless explicitly defined otherwise.
431446Given that remote DNS resolution is assumed to be the preferred mode, all
432- other examples explicitly disable DNS resoltion like this:
447+ other examples explicitly disable DNS resolution like this:
433448
434449``` php
450+ $proxy = new Clue\React\Socks\Client(
451+ '127.0.0.1:1080',
452+ new React\Socket\Connector($loop)
453+ );
454+
435455$connector = new React\Socket\Connector($loop, array(
436- 'tcp' => $client ,
456+ 'tcp' => $proxy ,
437457 'dns' => false
438458));
439459```
@@ -442,9 +462,14 @@ If you want to explicitly use *local DNS resolution* (such as when explicitly
442462using SOCKS4), you can use the following code:
443463
444464``` php
465+ $proxy = new Clue\React\Socks\Client(
466+ '127.0.0.1:1080',
467+ new React\Socket\Connector($loop)
468+ );
469+
445470// set up Connector which uses Google's public DNS (8.8.8.8)
446471$connector = new React\Socket\Connector($loop, array(
447- 'tcp' => $client ,
472+ 'tcp' => $proxy ,
448473 'dns' => '8.8.8.8'
449474));
450475```
@@ -475,7 +500,7 @@ so this methods should not be used on a network where you have to worry about ea
475500You can simply pass the authentication information as part of the SOCKS URI:
476501
477502``` php
478- $
client = new Clue\React\Socks\Client('username:
[email protected] ', $connector);
503+ $
proxy = new Clue\React\Socks\Client('username:
[email protected] ', $connector);
479504```
480505
481506Note that both the username and password must be percent-encoded if they contain
@@ -485,7 +510,7 @@ special characters:
485510$user = 'he:llo';
486511$pass = 'p@ss';
487512
488- $client = new Clue\React\Socks\Client(
513+ $proxy = new Clue\React\Socks\Client(
489514 rawurlencode($user) . ':' . rawurlencode($pass) . '@127.0.0.1',
490515 $connector
491516);
@@ -589,8 +614,13 @@ It provides the same `connect()` method, but will automatically reject the
589614underlying connection attempt if it takes too long:
590615
591616``` php
617+ $proxy = new Clue\React\Socks\Client(
618+ '127.0.0.1:1080',
619+ new React\Socket\Connector($loop)
620+ );
621+
592622$connector = new React\Socket\Connector($loop, array(
593- 'tcp' => $client ,
623+ 'tcp' => $proxy ,
594624 'dns' => false,
595625 'timeout' => 3.0
596626));
@@ -632,12 +662,12 @@ You can use the `sockss://` URI scheme or use an explicit
632662[ SOCKS protocol version] ( #protocol-version ) like this:
633663
634664``` php
635- $client = new Clue\React\Socks\Client(
665+ $proxy = new Clue\React\Socks\Client(
636666 'sockss://127.0.0.1:1080',
637667 new React\Socket\Connector($loop)
638668);
639669
640- $client = new Clue\React\Socks\Client(
670+ $proxy = new Clue\React\Socks\Client(
641671 'socks4s://127.0.0.1:1080',
642672 new React\Socket\Connector($loop)
643673);
@@ -649,7 +679,7 @@ Similarly, you can also combine this with [authentication](#authentication)
649679like this:
650680
651681``` php
652- $client = new Clue\React\Socks\Client(
682+ $proxy = new Clue\React\Socks\Client(
653683 'sockss://user:
[email protected] :1080',
654684 new React\Socket\Connector($loop)
655685);
@@ -684,12 +714,12 @@ You can use the `socks+unix://` URI scheme or use an explicit
684714[ SOCKS protocol version] ( #protocol-version ) like this:
685715
686716``` php
687- $client = new Clue\React\Socks\Client(
717+ $proxy = new Clue\React\Socks\Client(
688718 'socks+unix:///tmp/proxy.sock'
689719 new React\Socket\Connector($loop)
690720);
691721
692- $client = new Clue\React\Socks\Client(
722+ $proxy = new Clue\React\Socks\Client(
693723 'socks4+unix:///tmp/proxy.sock',
694724 new React\Socket\Connector($loop)
695725);
@@ -699,7 +729,7 @@ Similarly, you can also combine this with [authentication](#authentication)
699729like this:
700730
701731``` php
702- $client = new Clue\React\Socks\Client(
732+ $proxy = new Clue\React\Socks\Client(
703733 'socks+unix://user:pass@/tmp/proxy.sock',
704734 new React\Socket\Connector($loop)
705735);
@@ -865,10 +895,10 @@ $loop = React\EventLoop\Factory::create();
865895
866896// set next SOCKS server example.com:1080 as target
867897$connector = new React\Socket\Connector($loop);
868- $
client = new Clue\React\Socks\Client('user:
[email protected] :1080', $connector);
898+ $
proxy = new Clue\React\Socks\Client('user:
[email protected] :1080', $connector);
869899
870900// start a new server which forwards all connections to the other SOCKS server
871- $server = new Clue\React\Socks\Server($loop, $client );
901+ $server = new Clue\React\Socks\Server($loop, $proxy );
872902
873903// listen on localhost:1080
874904$socket = new React\Socket\Server('127.0.0.1:1080', $loop);
@@ -1005,7 +1035,18 @@ $ ssh -D 1080 example.com
10051035Now you can simply use this SSH SOCKS server like this:
10061036
10071037``` PHP
1008- $client = new Clue\React\Socks\Client('127.0.0.1:1080', $connector);
1038+ $proxy = new Clue\React\Socks\Client(
1039+ '127.0.0.1:1080',
1040+ new React\Socket\Connector($loop)
1041+ );
1042+
1043+ $proxy->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
1044+ $connection->write("GET / HTTP/1.0\r\n\r\n");
1045+
1046+ $connection->on('data', function ($chunk) {
1047+ echo $chunk;
1048+ });
1049+ });
10091050```
10101051
10111052Note that the above will allow all users on the local system to connect over
@@ -1021,7 +1062,18 @@ $ ssh -D/tmp/proxy.sock example.com
10211062Now you can simply use this SSH SOCKS server like this:
10221063
10231064``` PHP
1024- $client = new Clue\React\Socks\Client('socks+unix:///tmp/proxy.sock', $connector);
1065+ $proxy = new Clue\React\Socks\Client(
1066+ 'socks+unix:///tmp/proxy.sock',
1067+ new React\Socket\Connector($loop)
1068+ );
1069+
1070+ $proxy->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
1071+ $connection->write("GET / HTTP/1.0\r\n\r\n");
1072+
1073+ $connection->on('data', function ($chunk) {
1074+ echo $chunk;
1075+ });
1076+ });
10251077```
10261078
10271079> As an alternative to requiring this manual setup, you may also want to look
@@ -1038,7 +1090,18 @@ It presents a SOCKS5 and SOCKS4(a) interface on TCP port 9050 by default
10381090which allows you to tunnel any traffic through the anonymity network:
10391091
10401092``` php
1041- $client = new Clue\React\Socks\Client('127.0.0.1:9050', $connector);
1093+ $proxy = new Clue\React\Socks\Client(
1094+ '127.0.0.1:9050',
1095+ new React\Socket\Connector($loop)
1096+ );
1097+
1098+ $proxy->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
1099+ $connection->write("GET / HTTP/1.0\r\n\r\n");
1100+
1101+ $connection->on('data', function ($chunk) {
1102+ echo $chunk;
1103+ });
1104+ });
10421105```
10431106
10441107In most common scenarios you probably want to stick to default
0 commit comments