webman是workerman的web开发框架
可以很容易的开启udp服务
tcp建议使用gatewayworker
webman GatewayWorker插件
创建udp服务:
config/process.php中加入:
return [
// File update detection and automatic reload
'monitor' => [
...........
],
'udp' => [
'handler' => process\Udp::class,
'reloadable' => true,
'listen' => 'udp://0.0.0.0:64001',
'count' => 2,
]
];
新建文件:process/Udp.php
<?php
namespace process;
use support\Log;
class Udp
{
public function onWorkerStart($worker)
{
Log::info(__METHOD__ . " worker:{$worker->id}");
}
public function onMessage($connection, $data)
{
Log::info(__METHOD__ . " msg:{$data}");
$connection->send('shoudao');
}
}
执行:
php start.php start
结果(我这里安装了gatewayworker插件):