udb 服务

<?php
/**
 * Created by PhpStorm.
 * User: zhangheg
 * Date: 2019/3/23
 * Time: 14:52
 */

$client = new Swoole\Client(SWOOLE_SOCK_UDP);
$client->sendto('127.0.0.1',9501,'客户端udp来了');
<?php
/**
 * Created by PhpStorm.
 * User: zhangheg
 * Date: 2019/3/23
 * Time: 17:45
 */
//创建Server对象,监听 0.0.0.0:9501端口
$serv = new swoole_server("0.0.0.0", 9501,SWOOLE_PROCESS,SWOOLE_SOCK_UDP);

$serv->set([
    'worker_num' => 1, //设置进程
    'heartbeat_check_interval'=>3, //心跳间隔时间
    'heartbeat_idle_time' => 15, //允许空闲时间 心跳的两倍,容错,允许一次丢包
]);


$serv->on('packet',function ($server,$data,$clientInfo){
    var_dump($data);
    var_dump($clientInfo);
    //$server->sendTo();
});
$serv->start();
class A{


    public function connect($serv, $fd){
        var_dump('classa连接');
        echo "有新的客户端连接,连接标识为$fd" . PHP_EOL;
    }
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注