Skip to content

Instantly share code, notes, and snippets.

@AnrDaemon
Created June 29, 2017 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnrDaemon/4d0c904d7f45441ce9f7af106659727b to your computer and use it in GitHub Desktop.
Save AnrDaemon/4d0c904d7f45441ce9f7af106659727b to your computer and use it in GitHub Desktop.
<?php
require_once __DIR__.'/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$factory = new React\Datagram\Factory($loop);
function serverHandler(React\Datagram\Socket $server) {
$server->on('message', 'messageHandler');
}
function messageHandler($message, $address, $server) {
$server->send('hello ' . $address . '! echo: ' . $message, $address);
echo 'client ' . $address . ': ' . $message . PHP_EOL;
}
$factory->createServer('localhost:1234')->then('serverHandler');
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment