Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 149 additions & 49 deletions README.md

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions examples/01-https-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
}

$loop = React\EventLoop\Factory::create();
$client = new Clue\React\Socks\Client($url, new React\Socket\Connector($loop));
$proxy = new Clue\React\Socks\Client(
$url,
new React\Socket\Connector($loop)
);

$connector = new React\Socket\Connector($loop, array(
'tcp' => $client,
'tcp' => $proxy,
'timeout' => 3.0,
'dns' => false
));
Expand All @@ -37,5 +40,5 @@
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});

$loop->run();
8 changes: 5 additions & 3 deletions examples/02-optional-proxy-https-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
$connector = null;
$url = getenv('socks_proxy');
if ($url !== false) {
$connector = new React\Socket\Connector($loop);
$client = new Clue\React\Socks\Client($url, $connector);
$proxy = new Clue\React\Socks\Client(
$url,
new React\Socket\Connector($loop)
);
$connector = new React\Socket\Connector($loop, array(
'tcp' => $client,
'tcp' => $proxy,
'timeout' => 3.0,
'dns' => false
));
Expand Down
13 changes: 8 additions & 5 deletions examples/11-proxy-raw-http-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@

$loop = React\EventLoop\Factory::create();

$client = new Clue\React\Socks\Client($url, new React\Socket\Connector($loop));
$proxy = new Clue\React\Socks\Client(
$url,
new React\Socket\Connector($loop)
);
$connector = new React\Socket\Connector($loop, array(
'tcp' => $client,
'tcp' => $proxy,
'timeout' => 3.0,
'dns' => false
));

echo 'Demo SOCKS client connecting to SOCKS server ' . $url . PHP_EOL;

$connector->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $stream) {
$connector->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
echo 'connected' . PHP_EOL;
$stream->write("GET / HTTP/1.0\r\n\r\n");
$stream->on('data', function ($data) {
$connection->write("GET / HTTP/1.0\r\n\r\n");
$connection->on('data', function ($data) {
echo $data;
});
}, function (Exception $e) {
Expand Down
10 changes: 5 additions & 5 deletions examples/12-optional-proxy-raw-http-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@

$url = getenv('socks_proxy');
if ($url !== false) {
$client = new Clue\React\Socks\Client($url, $connector);
$proxy = new Clue\React\Socks\Client($url, $connector);
$connector = new React\Socket\Connector($loop, array(
'tcp' => $client,
'tcp' => $proxy,
'timeout' => 3.0,
'dns' => false
));
}

echo 'Demo SOCKS client connecting to SOCKS server ' . $url . PHP_EOL;

$connector->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $stream) {
$connector->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
echo 'connected' . PHP_EOL;
$stream->write("GET / HTTP/1.0\r\n\r\n");
$stream->on('data', function ($data) {
$connection->write("GET / HTTP/1.0\r\n\r\n");
$connection->on('data', function ($data) {
echo $data;
});
}, function (Exception $e) {
Expand Down
13 changes: 8 additions & 5 deletions examples/13-proxy-raw-https-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@

$loop = React\EventLoop\Factory::create();

$client = new Clue\React\Socks\Client($url, new React\Socket\Connector($loop));
$proxy = new Clue\React\Socks\Client(
$url,
new React\Socket\Connector($loop)
);
$connector = new React\Socket\Connector($loop, array(
'tcp' => $client,
'tcp' => $proxy,
'timeout' => 3.0,
'dns' => false
));

echo 'Demo SOCKS client connecting to SOCKS server ' . $url . PHP_EOL;

$connector->connect('tls://www.google.com:443')->then(function (React\Socket\ConnectionInterface $stream) {
$connector->connect('tls://www.google.com:443')->then(function (React\Socket\ConnectionInterface $connection) {
echo 'connected' . PHP_EOL;
$stream->write("GET / HTTP/1.0\r\n\r\n");
$stream->on('data', function ($data) {
$connection->write("GET / HTTP/1.0\r\n\r\n");
$connection->on('data', function ($data) {
echo $data;
});
}, function (Exception $e) {
Expand Down
10 changes: 5 additions & 5 deletions examples/14-optional-proxy-raw-https-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@

$url = getenv('socks_proxy');
if ($url !== false) {
$client = new Clue\React\Socks\Client($url, $connector);
$proxy = new Clue\React\Socks\Client($url, $connector);
$connector = new React\Socket\Connector($loop, array(
'tcp' => $client,
'tcp' => $proxy,
'timeout' => 3.0,
'dns' => false
));
}

echo 'Demo SOCKS client connecting to SOCKS server ' . $url . PHP_EOL;

$connector->connect('tls://www.google.com:443')->then(function (React\Socket\ConnectionInterface $stream) {
$connector->connect('tls://www.google.com:443')->then(function (React\Socket\ConnectionInterface $connection) {
echo 'connected' . PHP_EOL;
$stream->write("GET / HTTP/1.0\r\n\r\n");
$stream->on('data', function ($data) {
$connection->write("GET / HTTP/1.0\r\n\r\n");
$connection->on('data', function ($data) {
echo $data;
});
}, function (Exception $e) {
Expand Down
6 changes: 3 additions & 3 deletions examples/15-proxy-chaining.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@

echo 'Demo SOCKS client connecting to SOCKS proxy server chain ' . implode(' -> ', $path) . PHP_EOL;

$connector->connect('tls://www.google.com:443')->then(function (React\Socket\ConnectionInterface $stream) {
$connector->connect('tls://www.google.com:443')->then(function (React\Socket\ConnectionInterface $connection) {
echo 'connected' . PHP_EOL;
$stream->write("GET / HTTP/1.0\r\n\r\n");
$stream->on('data', function ($data) {
$connection->write("GET / HTTP/1.0\r\n\r\n");
$connection->on('data', function ($data) {
echo $data;
});
}, function (Exception $e) {
Expand Down
17 changes: 10 additions & 7 deletions examples/16-local-dns.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@
// A simple example which requests https://www.google.com/ through a SOCKS proxy with local DNS resolution.
// The proxy can be given as first argument and defaults to localhost:1080 otherwise.
//
// Not already running a SOCKS proxy server? See also example #21 or try this:
// Not already running a SOCKS proxy server? See also example #21 or try this:
// $ ssh -D 1080 localhost
//
// For illustration purposes only. If you want to send HTTP requests in a real
// world project, take a look at example #01, example #02 and https://github.com/reactphp/http#client-usage.

require __DIR__ . '/../vendor/autoload.php';

$proxy = isset($argv[1]) ? $argv[1] : '127.0.0.1:1080';
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:1080';

$loop = React\EventLoop\Factory::create();

// set up DNS server to use (Google's public DNS)
$client = new Clue\React\Socks\Client($proxy, new React\Socket\Connector($loop));
$proxy = new Clue\React\Socks\Client(
$url,
new React\Socket\Connector($loop)
);
$connector = new React\Socket\Connector($loop, array(
'tcp' => $client,
'tcp' => $proxy,
'timeout' => 3.0,
'dns' => '8.8.8.8'
));

echo 'Demo SOCKS client connecting to SOCKS server ' . $proxy . PHP_EOL;

$connector->connect('tls://www.google.com:443')->then(function (React\Socket\ConnectionInterface $stream) {
$connector->connect('tls://www.google.com:443')->then(function (React\Socket\ConnectionInterface $connection) {
echo 'connected' . PHP_EOL;
$stream->write("GET / HTTP/1.0\r\n\r\n");
$stream->on('data', function ($data) {
$connection->write("GET / HTTP/1.0\r\n\r\n");
$connection->on('data', function ($data) {
echo $data;
});
}, function (Exception $e) {
Expand Down
6 changes: 3 additions & 3 deletions examples/32-server-proxy-chaining-from-random-pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
// forward to socks server listening on 127.0.0.1:9051-9053
// this connector randomly picks one of the the attached connectors from the pool
$connector = new React\Socket\Connector($loop);
$clients = array();
$proxies = array();
foreach ($pool as $proxy) {
$clients []= new Clue\React\Socks\Client($proxy, $connector);
$proxies []= new Clue\React\Socks\Client($proxy, $connector);
}
$connector = new ConnectionManager\Extra\Multiple\ConnectionManagerRandom($clients);
$connector = new ConnectionManager\Extra\Multiple\ConnectionManagerRandom($proxies);

// start the SOCKS proxy server using our connection manager for outgoing connections
$server = new Clue\React\Socks\Server($loop, $socket, $connector);
Expand Down
21 changes: 12 additions & 9 deletions examples/42-http-secure.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,29 @@

require __DIR__ . '/../vendor/autoload.php';

$proxy = isset($argv[1]) ? $argv[1] : '127.0.0.1:1080';
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:1080';

$loop = React\EventLoop\Factory::create();

$client = new Clue\React\Socks\Client('sockss://' . $proxy, new React\Socket\Connector($loop, array('tls' => array(
'verify_peer' => false,
'verify_peer_name' => false
))));
$proxy = new Clue\React\Socks\Client(
'sockss://' . $url,
new React\Socket\Connector($loop, array('tls' => array(
'verify_peer' => false,
'verify_peer_name' => false
)))
);
$connector = new React\Socket\Connector($loop, array(
'tcp' => $client,
'tcp' => $proxy,
'timeout' => 3.0,
'dns' => false
));

echo 'Demo SOCKS over TLS client connecting to secure SOCKS server ' . $proxy . PHP_EOL;

$connector->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $stream) {
$connector->connect('tcp://www.google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
echo 'connected' . PHP_EOL;
$stream->write("GET / HTTP/1.0\r\n\r\n");
$stream->on('data', function ($data) {
$connection->write("GET / HTTP/1.0\r\n\r\n");
$connection->on('data', function ($data) {
echo $data;
});
}, function (Exception $e) {
Expand Down