<?php

require_once __DIR__.'/../vendor/autoload.php';

$loop = React\EventLoop\Factory::create();

$factory = new Datagram\Factory($loop);

$factory->createServer(1234)->then(function (Datagram\Server $server) {
    $server->on('message', function($message, $client) {
        $client->send('hello '.$client->getAddress().'! echo: '.$message);

        // $server->send() is not available here
    });
});

$loop->run();

<?php

require_once __DIR__.'/../vendor/autoload.php';

$loop = React\EventLoop\Factory::create();

$factory = new Datagram\Factory($loop);

$factory->createServer(1234)->then(function (Datagram\Server $server) {
    $server->on('message', function($message, $client) {
        $client->send('hello '.$client->getAddress().'! echo: '.$message);

        echo 'client ' . $client->getAddress() . ': ' . $message . PHP_EOL;
    });
});

$loop->run();

Extend example to echo received client messages
Extend example to echo received client messages