Skip to content

Simple multicast UDP messages, built on top of React PHP

License

Notifications You must be signed in to change notification settings

clue-labs/reactphp-multicast

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clue/multicast-react Build Status

Multicast UDP messages, built on top of React PHP.

Multicast UDP messages are needed for quite a few (low-level) networking protocols. This library exposes a simple subset of commonly needed functionality for multicast networking through an easy to use API.

Among others, multicast networking is the basis for:

  • MDNS (Multicast DNS)
  • HTTPU/HTTPMU (Multicast and Unicast UDP HTTP Messages)
  • UPNP/SSDP (Univeral Plug and Play / Simple Service Discovery Protocol).

Note: This project is in early alpha stage! Feel free to report any issues you encounter.

Quickstart example

Once installed, you can use the following code to create a simple echo server that listens for incoming multicast messages:

$loop = React\EventLoop\Factory::create();
$factory = new Factory($loop);
$socket = $factory->createReceiver('224.10.20.30:4050');

$socket->on('message', function ($data, $remote) use ($socket) {
    echo 'Sending back ' . strlen($data) . ' bytes to ' . $remote . PHP_EOL;
    $socket->send($data, $remote);
});

$loop->run();

See also the examples.

Description

PHP 5.4 added support for the required multicast socket options and constants.

These options are only available to the low level socket API (ext-sockets), not to the newer stream based networking API. Because of this, this library depends on sockets based on ext-sockets, provided via clue/socket-react and clue/socket-raw.

For the most part, React PHP is built around the general purpose stream based API and has only somewhat limited support for the low level socket API. The package clue/socket-react works around this for the most part. Simply put, you should try to avoid using the default StreamSelectLoop, as it requires a workaround to poll the socket resources via a periodic timer every 10ms.

This library also provides somewhat limited support for PHP 5.3. While this version lacks the required socket options and constants for listening on multicast addresses for incoming messages, its underlying socket API is still level 1 multicast conformant. This means that it can be used for sending outgoing packages to multicast addresses and receiving incoming unicast responses in return.

Install

The recommended way to install this library is through composer. New to composer?

{
    "require": {
        "clue/multicast-react": "dev-master"
    }
}

License

MIT

About

Simple multicast UDP messages, built on top of React PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%