-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsend-wait.php
More file actions
24 lines (19 loc) · 720 Bytes
/
send-wait.php
File metadata and controls
24 lines (19 loc) · 720 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 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)
*/
require __DIR__ . '/../vendor/autoload.php';
$address = isset($argv[1]) ? $argv[1] : '224.10.20.30:12345';
$factory = new Clue\React\Multicast\Factory();
$sender = $factory->createSender();
$hex = new Clue\Hexdump\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);