|
| 1 | +# clue/multicast-react [](https://travis-ci.org/clue/php-multicast-react) |
| 2 | + |
| 3 | +Multicast UDP messages, built on top of [React PHP](http://reactphp.org/). |
| 4 | + |
| 5 | +Multicast UDP messages are needed for quite a few (low-level) networking protocols. |
| 6 | +This library exposes a simple subset of commonly needed functionality for |
| 7 | +multicast networking through an easy to use API. |
| 8 | + |
| 9 | +Among others, multicast networking is the basis for: |
| 10 | + |
| 11 | +* MDNS (Multicast DNS) |
| 12 | +* HTTPU/HTTPMU (Multicast and Unicast UDP HTTP Messages) |
| 13 | +* UPNP/SSDP (Univeral Plug and Play / Simple Service Discovery Protocol). |
| 14 | + |
| 15 | +> Note: This project is in early alpha stage! Feel free to report any issues you encounter. |
| 16 | +
|
| 17 | +## Quickstart example |
| 18 | + |
| 19 | +Once [installed](#install), you can use the following code to create a simple |
| 20 | +echo server that listens for incoming multicast messages: |
| 21 | + |
| 22 | +```php |
| 23 | +$loop = React\EventLoop\Factory::create(); |
| 24 | +$factory = new Factory($loop); |
| 25 | +$socket = $factory->createReceiver('224.10.20.30:4050'); |
| 26 | + |
| 27 | +$socket->on('message', function ($data, $remote) use ($socket) { |
| 28 | + echo 'Sending back ' . strlen($data) . ' bytes to ' . $remote . PHP_EOL; |
| 29 | + $socket->send($data, $remote); |
| 30 | +}); |
| 31 | + |
| 32 | +$loop->run(); |
| 33 | +``` |
| 34 | + |
| 35 | +See also the [examples](examples). |
| 36 | + |
| 37 | +## Description |
| 38 | + |
| 39 | +[PHP 5.4 added support](http://php.net/manual/en/migration54.global-constants.php) |
| 40 | +for the required multicast socket options and constants. |
| 41 | + |
| 42 | +These options are only available to the low level socket API (ext-sockets), not |
| 43 | +to the newer stream based networking API. |
| 44 | +Because of this, this library depends on sockets based on `ext-sockets`, provided |
| 45 | +via [clue/socket-react](https://github.com/clue/php-socket-react) |
| 46 | +and [clue/socket-raw](https://github.com/clue/php-socket-raw). |
| 47 | + |
| 48 | +For the most part, React PHP is built around the general purpose stream based API |
| 49 | +and has only somewhat limited support for the low level socket API. |
| 50 | +The package [clue/socket-react](https://github.com/clue/php-socket-react) |
| 51 | +works around this for the most part. |
| 52 | +Simply put, you should try to avoid using the default `StreamSelectLoop`, |
| 53 | +as it requires a workaround to poll the socket resources via a periodic timer |
| 54 | +every 10ms. |
| 55 | + |
| 56 | +This library also provides somewhat limited support for PHP 5.3. |
| 57 | +While this version lacks the required socket options and constants for listening |
| 58 | +on multicast addresses for incoming messages, its underlying socket API is still |
| 59 | +[level 1 multicast conformant](http://www.tldp.org/HOWTO/Multicast-HOWTO-2.html#ss2.2). |
| 60 | +This means that it can be used for sending outgoing packages to multicast addresses |
| 61 | +and receiving incoming unicast responses in return. |
| 62 | + |
| 63 | +## Install |
| 64 | + |
| 65 | +The recommended way to install this library is [through composer](http://getcomposer.org). [New to composer?](http://getcomposer.org/doc/00-intro.md) |
| 66 | + |
| 67 | +```JSON |
| 68 | +{ |
| 69 | + "require": { |
| 70 | + "clue/multicast-react": "dev-master" |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +## License |
| 76 | + |
| 77 | +MIT |
0 commit comments