UDP

UDP为应用程序提供了一种无需建立连接就可以发送封装的IP数据包的方法。

EasySwooleEventmainServerCreate事件,进行子服务监听:

  1. public static function mainServerCreate(\EasySwoole\EasySwoole\Swoole\EventRegister $register)
  2. {
  3. $server = \EasySwoole\EasySwoole\ServerManager::getInstance()->getSwooleServer();
  4. $subPort = $server->addlistener('0.0.0.0', 9503, SWOOLE_UDP);
  5. $subPort->on($register::onPacket, function (\Swoole\Server $server, string $data, array $clientInfo) {
  6. $server->sendto($clientInfo['address'], $clientInfo['port'], 'Server:' . $data);
  7. });
  8. }