-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathecho-received.php
More file actions
24 lines (19 loc) · 780 Bytes
/
echo-received.php
File metadata and controls
24 lines (19 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
/**
* Simple receiving socket example server that sends back every message it received
*
* Accepts a single argument socket address (defaults to 224.10.20.30:12345)
*/
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];
}
$factory = new Clue\React\Multicast\Factory();
$socket = $factory->createReceiver($address);
$socket->on('message', function ($data, $remote) use ($socket) {
echo 'Sending back ' . strlen($data) . ' bytes to ' . $remote . PHP_EOL;
$socket->send($data, $remote);
});