' . PHP_EOL); exit(1); } $connector = new Connector(); $stdin = new ReadableResourceStream(STDIN); $stdin->pause(); $stdout = new WritableResourceStream(STDOUT); $stderr = new WritableResourceStream(STDERR); $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 (Exception $e) use ($stderr) { $stderr->write('Stream error: ' . $e->getMessage() . 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 (Exception $e) use ($stderr) { $stderr->write('Connection error: ' . $e->getMessage() . PHP_EOL); });