@@ -43,7 +43,8 @@ to google.com via a local SOCKS proxy server:
4343
4444``` php
4545$loop = React\EventLoop\Factory::create();
46- $client = new Client('127.0.0.1:1080', new Connector($loop));
46+ $connector = new React\Socket\Connector($loop);
47+ $client = new Clue\React\Socks\Client('127.0.0.1:1080', $connector);
4748
4849$client->connect('tcp://www.google.com:80')->then(function (ConnectionInterface $stream) {
4950 $stream->write("GET / HTTP/1.0\r\n\r\n");
@@ -59,11 +60,12 @@ proxy server listening for connections on `localhost:1080`:
5960``` php
6061$loop = React\EventLoop\Factory::create();
6162
62- // listen on localhost:1080
63- $socket = new Socket('127.0.0.1:1080', $loop);
63+ // start a new SOCKS proxy server
64+ $server = new Clue\React\Socks\Server( $loop);
6465
65- // start a new server listening for incoming connection on the given socket
66- $server = new Server($loop, $socket);
66+ // listen on localhost:1080
67+ $socket = new React\Socket\Server('127.0.0.1:1080', $loop);
68+ $server->listen($socket);
6769
6870$loop->run();
6971```
@@ -93,20 +95,17 @@ You can omit the port if you're using the default SOCKS port 1080:
9395$client = new Client('127.0.0.1', $connector);
9496```
9597
96- If you need custom connector settings (DNS resolution, timeouts etc.), you can explicitly pass a
97- custom instance of the [ ` ConnectorInterface ` ] ( https://github.com/reactphp/socket#connectorinterface ) :
98+ If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
99+ proxy servers etc.), you can explicitly pass a custom instance of the
100+ [ ` ConnectorInterface ` ] ( https://github.com/reactphp/socket#connectorinterface ) :
98101
99102``` php
100- // use local DNS server
101- $dnsResolverFactory = new DnsFactory();
102- $resolver = $dnsResolverFactory->createCached('127.0.0.1', $loop);
103-
104- // outgoing connections to SOCKS server via interface 192.168.10.1
105- // this is not to be confused with local DNS resolution (see further below)
106- $connector = new DnsConnector(
107- new TcpConnector($loop, array('bindto' => '192.168.10.1:0')),
108- $resolver
109- );
103+ $connector = new React\Socket\Connector($loop, array(
104+ 'dns' => '127.0.0.1',
105+ 'tcp' => array(
106+ 'bindto' => '192.168.10.1:0'
107+ )
108+ ));
110109
111110$client = new Client('my-socks-server.local:1080', $connector);
112111```
@@ -622,12 +621,15 @@ It also registers everything with the main [`EventLoop`](https://github.com/reac
622621and an underlying TCP/IP socket server like this:
623622
624623``` php
625- $loop = \React\EventLoop\Factory::create();
624+ $loop = React\EventLoop\Factory::create();
625+
626+ $server = new Clue\React\Socks\Server($loop);
626627
627628// listen on localhost:$port
628- $socket = new Socket($port, $loop);
629+ $socket = new React\Socket\Server($port, $loop);
630+ $server->listen($socket);
629631
630- $server = new Server($ loop, $socket );
632+ $loop->run( );
631633```
632634
633635#### Server connector
@@ -636,21 +638,19 @@ The `Server` uses an instance of ReactPHP's
636638[ ` ConnectorInterface ` ] ( https://github.com/reactphp/socket#connectorinterface )
637639to establish outgoing connections for each incoming connection request.
638640
639- If you need custom connector settings (DNS resolution, timeouts etc.), you can explicitly pass a
640- custom instance of the [ ` ConnectorInterface ` ] ( https://github.com/reactphp/socket#connectorinterface ) :
641+ If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
642+ proxy servers etc.), you can explicitly pass a custom instance of the
643+ [ ` ConnectorInterface ` ] ( https://github.com/reactphp/socket#connectorinterface ) :
641644
642645``` php
643- // use local DNS server
644- $dnsResolverFactory = new DnsFactory();
645- $resolver = $dnsResolverFactory->createCached('127.0.0.1', $loop);
646-
647- // outgoing connections to target host via interface 192.168.10.1
648- $connector = new DnsConnector(
649- new TcpConnector($loop, array('bindto' => '192.168.10.1:0')),
650- $resolver
651- );
646+ $connector = new React\Socket\Connector($loop, array(
647+ 'dns' => '127.0.0.1',
648+ 'tcp' => array(
649+ 'bindto' => '192.168.10.1:0'
650+ )
651+ ));
652652
653- $server = new Server($loop, $socket , $connector);
653+ $server = new Clue\React\Socks\ Server($loop, $connector);
654654```
655655
656656If you want to forward the outgoing connection through another SOCKS proxy, you
@@ -758,15 +758,20 @@ In order to connect through another SOCKS server, you can simply use the
758758You can create a SOCKS ` Client ` instance like this:
759759
760760``` php
761+ $loop = React\EventLoop\Factory::create();
762+
761763// set next SOCKS server example.com:1080 as target
762764$connector = new React\Socket\Connector($loop);
763- $client = new Client('user:pass@example.com:1080', $connector);
765+ $client = new Clue\React\Socks\Client('user:pass@example.com:1080', $connector);
766+
767+ // start a new server which forwards all connections to the other SOCKS server
768+ $server = new Clue\React\Socks\Server($loop, $client);
764769
765770// listen on localhost:1080
766- $socket = new Socket('127.0.0.1:1080', $loop);
771+ $socket = new React\Socket\Server('127.0.0.1:1080', $loop);
772+ $server->listen($socket);
767773
768- // start a new server which forwards all connections to the other SOCKS server
769- $server = new Server($loop, $socket, $client);
774+ $loop->run();
770775```
771776
772777See also [ example #21 ] ( examples ) .
@@ -807,15 +812,19 @@ details.
807812You can simply start your listening socket on the ` tls:// ` URI scheme like this:
808813
809814``` php
810- $loop = \React\EventLoop\Factory::create();
815+ $loop = React\EventLoop\Factory::create();
816+
817+ $server = new Clue\React\Socks\Server($loop);
811818
812819// listen on tls://127.0.0.1:1080 with the given server certificate
813820$socket = new React\Socket\Server('tls://127.0.0.1:1080', $loop, array(
814821 'tls' => array(
815822 'local_cert' => __DIR__ . '/localhost.pem',
816823 )
817824));
818- $server = new Server($loop, $socket);
825+ $server->listen($socket);
826+
827+ $loop->run();
819828```
820829
821830See also [ example 31] ( examples ) .
@@ -842,11 +851,15 @@ having to rely on explicit [authentication](#server-authentication).
842851You can simply start your listening socket on the ` unix:// ` URI scheme like this:
843852
844853``` php
845- $loop = \React\EventLoop\Factory::create();
854+ $loop = React\EventLoop\Factory::create();
855+
856+ $server = new Clue\React\Socks\Server($loop);
846857
847858// listen on /tmp/proxy.sock
848859$socket = new React\Socket\Server('unix:///tmp/proxy.sock', $loop);
849- $server = new Server($loop, $socket);
860+ $server->listen($socket);
861+
862+ $loop->run();
850863```
851864
852865> Note that Unix domain sockets (UDS) are considered advanced usage and that
0 commit comments