Esempio n. 1
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();
Esempio n. 2
0
<?php

/**
 * Simple receiving example socket server that prints a hexdump of every message received
 *
 * 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 = '224.10.20.30:12345';
// random test address
//$address = '239.255.255.250:1900'; // UPNP SSDP (simple service discovery protocol)
// use either above default address or the one given as first argument to this script
if (isset($argv[1])) {
    $address = $argv[1];
}
$loop = React\EventLoop\Factory::create();
$factory = new Factory($loop);
$socket = $factory->createReceiver($address);
$hex = new Hexdump();
$socket->on('message', function ($data, $remote) use($hex) {
    echo 'Received from ' . $remote . PHP_EOL;
    echo $hex->dump($data) . PHP_EOL;
});
$loop->run();