标签:gateway ddr request 根据 命令 后端 register worker inf
composer create-project topthink/think=5.1.* tp5
composer require workerman/gateway-worker
启动停止命令:http://doc2.workerman.net/326106
a)前端进行登录并请求后端绑定 用户登录后初始化以及绑定client_id(前端监听ws://xxx.xxx.xxx.xxx:8282端口,代码省略)
public function bind()
{
// 设置GatewayWorker服务的Register服务ip和端口,请根据实际情况改成实际值
\GatewayWorker\Lib\Gateway::$registerAddress = '127.0.0.1:1238';
$this->uid = '111'; //假数据
$client_id = Request::param('client_id');
// client_id与uid绑定
\GatewayWorker\Lib\Gateway::bindUid($client_id, $uid);
// 加入某个群组(可调用多次加入多个群组)
//$group_id = $this->groupId;
//Gateway::joinGroup($client_id, $group_id);
}
b)前端进行操作(节目投票、聊天等等)
c)调用后端对应方法
d)一系列业务操作后,推送
$message = ['code'=>0,'msg'=>'投票成功'];
\GatewayWorker\Lib\Gateway::$registerAddress = '127.0.0.1:1238';
\GatewayWorker\Lib\Gateway::sendToUid($this->uid,json_encode($message)); //这一步可以省略
标签:gateway ddr request 根据 命令 后端 register worker inf
原文地址:https://www.cnblogs.com/L-ran/p/12149635.html