Skip to content

Update examples to use Stream v0.6 API #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2017
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
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,6 @@ $promise->cancel();
Calling `cancel()` on a pending promise will cancel the underlying DNS lookup
and/or the underlying TCP/IP connection and reject the resulting promise.

The legacy `Connector` class can be used for backwards-compatiblity reasons.
It works very much like the newer `DnsConnector` but instead has to be
set up like this:

```php
$connector = new React\SocketClient\Connector($loop, $dns);

$connector->connect('www.google.com:80')->then($callback);
```

> Advanced usage: Internally, the `DnsConnector` relies on a `Resolver` to
look up the IP address for the given hostname.
It will then replace the hostname in the destination URI with this IP and
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"require-dev": {
"clue/block-react": "^1.1",
"react/socket": "^0.5",
"phpunit/phpunit": "~4.8"
"phpunit/phpunit": "~4.8",
"react/stream": "^0.6"
}
}
11 changes: 5 additions & 6 deletions examples/03-netcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use React\EventLoop\Factory;
use React\SocketClient\Connector;
use React\SocketClient\ConnectionInterface;
use React\Stream\Stream;
use React\Stream\ReadableResourceStream;
use React\Stream\WritableResourceStream;

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

Expand All @@ -15,12 +16,10 @@
$loop = Factory::create();
$connector = new Connector($loop);

$stdin = new Stream(STDIN, $loop);
$stdin = new ReadableResourceStream(STDIN, $loop);
$stdin->pause();
$stdout = new Stream(STDOUT, $loop);
$stdout->pause();
$stderr = new Stream(STDERR, $loop);
$stderr->pause();
$stdout = new WritableResourceStream(STDOUT, $loop);
$stderr = new WritableResourceStream(STDERR, $loop);

$stderr->write('Connecting' . PHP_EOL);

Expand Down
5 changes: 2 additions & 3 deletions examples/04-web.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use React\EventLoop\Factory;
use React\SocketClient\ConnectionInterface;
use React\SocketClient\Connector;
use React\Stream\Stream;
use React\Stream\WritableResourceStream;

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

Expand Down Expand Up @@ -36,8 +36,7 @@
$resource .= '?' . $parts['query'];
}

$stdout = new Stream(STDOUT, $loop);
$stdout->pause();
$stdout = new WritableResourceStream(STDOUT, $loop);

$connector->connect($target)->then(function (ConnectionInterface $connection) use ($resource, $host, $stdout) {
$connection->pipe($stdout);
Expand Down