UdpServer.php 638 B

12345678910111213141516171819202122
  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::$pidFile = sprintf('%s/test-udp-server.pid', sys_get_temp_dir());
  13. Worker::$logFile = sprintf('%s/test-udp-server.log', sys_get_temp_dir());
  14. Worker::$command = 'start';
  15. Worker::runAll();