Esempio n. 1
0
    public function testBinaryMixedString()
    {
        $dumper = new Hexdump();
        $expected = <<<EOT
0000  74 68 69 73 0a 0d 63 6f  6e 74 61 69 6e 73 00 01   this..co ntains..
0010  02 03 62 69 6e 61 72 79                            ..binary

EOT;
        $this->assertEquals($expected, $dumper->dump("this\n\rcontainsbinary"));
        $expectedHtml = <<<EOT
<pre>
0000  74 68 69 73 0a 0d 63 6f  6e 74 61 69 6e 73 00 01   this..co ntains..
0010  02 03 62 69 6e 61 72 79                            ..binary
</pre>

EOT;
        $this->assertEquals($expectedHtml, $dumper->dumpHtml("this\n\rcontainsbinary"));
    }
Esempio n. 2
0
use Clue\React\Tar\Decoder;
use React\Stream\BufferedSink;
use Clue\Hexdump\Hexdump;
use React\EventLoop\StreamSelectLoop;
require __DIR__ . '/../vendor/autoload.php';
$in = isset($argv[1]) ? $argv[1] : __DIR__ . '/../tests/fixtures/alice-bob.tar';
echo 'Reading file "' . $in . '" (pass as argument to example)' . PHP_EOL;
// using the default loop does *not* work for file I/O
//$loop = Factory::create();
$loop = new StreamSelectLoop();
$stream = new Stream(fopen($in, 'r'), $loop);
$decoder = new Decoder();
$decoder->on('entry', function ($header, $file) {
    static $i = 0;
    echo 'FILE #' . ++$i . PHP_EOL;
    echo 'Received entry headers:' . PHP_EOL;
    var_dump($header);
    BufferedSink::createPromise($file)->then(function ($contents) {
        echo 'Received entry contents (' . strlen($contents) . ' bytes)' . PHP_EOL;
        $d = new Hexdump();
        echo $d->dump($contents) . PHP_EOL . PHP_EOL;
    });
});
$decoder->on('error', function ($error) {
    echo 'ERROR: ' . $error . PHP_EOL;
});
$decoder->on('close', function () {
    echo 'CLOSED' . PHP_EOL;
});
$stream->pipe($decoder);
$loop->run();
Esempio n. 3
0
<?php

/**
 * Simple sending socket example that sends a single message and then prints a hexdump of every response it receives
 *
 * Accepts a single argument socket address (defaults to 224.10.20.30:12345)
 */
use Clue\React\Multicast\Factory;
use Clue\Hexdump\Hexdump;
require __DIR__ . '/../vendor/autoload.php';
$address = isset($argv[1]) ? $argv[1] : '224.10.20.30:12345';
$loop = React\EventLoop\Factory::create();
$factory = new Factory($loop);
$sender = $factory->createSender();
$hex = new Hexdump();
// print a hexdump of every message received
$sender->on('message', function ($data, $remote) use($hex) {
    echo 'Received from ' . $remote . PHP_EOL;
    echo $hex->dump($data) . PHP_EOL;
});
// send a simple message
$message = 'ping 123';
$sender->send($message, $address);
$loop->run();