diff options
author | marvin-borner@live.com | 2018-04-16 21:09:05 +0200 |
---|---|---|
committer | marvin-borner@live.com | 2018-04-16 21:09:05 +0200 |
commit | cf14306c2b3f82a81f8d56669a71633b4d4b5fce (patch) | |
tree | 86700651aa180026e89a66064b0364b1e4346f3f /assets/php/vendor/react/socket/examples/02-chat-server.php | |
parent | 619b01b3615458c4ed78bfaeabb6b1a47cc8ad8b (diff) |
Main merge to user management system - files are now at /main/public/
Diffstat (limited to 'assets/php/vendor/react/socket/examples/02-chat-server.php')
-rwxr-xr-x | assets/php/vendor/react/socket/examples/02-chat-server.php | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/assets/php/vendor/react/socket/examples/02-chat-server.php b/assets/php/vendor/react/socket/examples/02-chat-server.php deleted file mode 100755 index 46439e0..0000000 --- a/assets/php/vendor/react/socket/examples/02-chat-server.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php - -// Just start this server and connect with any number of clients to it. -// Everything a client sends will be broadcasted to all connected clients. -// -// $ php examples/02-chat-server.php 8000 -// $ telnet localhost 8000 -// -// You can also run a secure TLS chat server like this: -// -// $ php examples/02-chat-server.php tls://127.0.0.1:8000 examples/localhost.pem -// $ openssl s_client -connect localhost:8000 -// -// You can also run a Unix domain socket (UDS) server like this: -// -// $ php examples/02-chat-server.php unix:///tmp/server.sock -// $ nc -U /tmp/server.sock - -use React\EventLoop\Factory; -use React\Socket\Server; -use React\Socket\ConnectionInterface; -use React\Socket\LimitingServer; - -require __DIR__ . '/../vendor/autoload.php'; - -$loop = Factory::create(); - -$server = new Server(isset($argv[1]) ? $argv[1] : 0, $loop, array( - 'tls' => array( - 'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem') - ) -)); - -$server = new LimitingServer($server, null); - -$server->on('connection', function (ConnectionInterface $client) use ($server) { - // whenever a new message comes in - $client->on('data', function ($data) use ($client, $server) { - // remove any non-word characters (just for the demo) - $data = trim(preg_replace('/[^\w\d \.\,\-\!\?]/u', '', $data)); - - // ignore empty messages - if ($data === '') { - return; - } - - // prefix with client IP and broadcast to all connected clients - $data = trim(parse_url($client->getRemoteAddress(), PHP_URL_HOST), '[]') . ': ' . $data . PHP_EOL; - foreach ($server->getConnections() as $connection) { - $connection->write($data); - } - }); -}); - -$server->on('error', 'printf'); - -echo 'Listening on ' . $server->getAddress() . PHP_EOL; - -$loop->run(); |