UdpServer.php 490 B

1234567891011121314151617181920
  1. <?php
  2. declare(strict_types=1);
  3. use Workerman\Worker;
  4. require './vendor/autoload.php';
  5. if(!defined('STDIN')) define('STDIN', fopen('php://stdin', 'r'));
  6. if(!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'w'));
  7. if(!defined('STDERR')) define('STDERR', fopen('php://stderr', 'w'));
  8. $server = new Worker('udp://127.0.0.1:8083');
  9. $server->onMessage = function ($connection, $data) {
  10. $connection->send('received: ' . $data);
  11. };
  12. Worker::$command = 'start';
  13. Worker::runAll();