From fc9401f04a3aca5abb22f87ebc210de8afe11d32 Mon Sep 17 00:00:00 2001 From: marvin-borner@live.com Date: Tue, 10 Apr 2018 21:50:16 +0200 Subject: Initial Commit --- .../react/socket/examples/21-netcat-client.php | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 assets/php/vendor/react/socket/examples/21-netcat-client.php (limited to 'assets/php/vendor/react/socket/examples/21-netcat-client.php') diff --git a/assets/php/vendor/react/socket/examples/21-netcat-client.php b/assets/php/vendor/react/socket/examples/21-netcat-client.php new file mode 100644 index 0000000..9140e2c --- /dev/null +++ b/assets/php/vendor/react/socket/examples/21-netcat-client.php @@ -0,0 +1,68 @@ +' . PHP_EOL); + exit(1); +} + +$loop = Factory::create(); +$connector = new Connector($loop); + +$stdin = new ReadableResourceStream(STDIN, $loop); +$stdin->pause(); +$stdout = new WritableResourceStream(STDOUT, $loop); +$stderr = new WritableResourceStream(STDERR, $loop); + +$stderr->write('Connecting' . PHP_EOL); + +$connector->connect($argv[1])->then(function (ConnectionInterface $connection) use ($stdin, $stdout, $stderr) { + // pipe everything from STDIN into connection + $stdin->resume(); + $stdin->pipe($connection); + + // pipe everything from connection to STDOUT + $connection->pipe($stdout); + + // report errors to STDERR + $connection->on('error', function ($error) use ($stderr) { + $stderr->write('Stream ERROR: ' . $error . PHP_EOL); + }); + + // report closing and stop reading from input + $connection->on('close', function () use ($stderr, $stdin) { + $stderr->write('[CLOSED]' . PHP_EOL); + $stdin->close(); + }); + + $stderr->write('Connected' . PHP_EOL); +}, function ($error) use ($stderr) { + $stderr->write('Connection ERROR: ' . $error . PHP_EOL); +}); + +$loop->run(); -- cgit v1.2.3