和网上其他文档不同之处
1.我是按照大神的教程配置. 但是出现了问题,问题如下,post请求都显示格式错误
2.修改之处,添加socket.io的参数,使其使用websocket模式通讯
基础环境
生成socket.io的监听类
通过tp的命令快速生成监听类
php think make:listener WebsocketTest
php think make:listener RoomLeave
php think make:listener RoomJoin
配置thinkphp-swoole
编辑监听类
三个类都差不多,主要是编辑 handle 这个方法
<?php
declare (strict_types = 1);
namespace app\listener;
use think\Container;
use think\swoole\Websocket;
class WebsocketTest
{
public $websocket = null;
/**
* 注入容器管理类,从容器中取出Websocket类,或者也可以直接注入Websocket类,
*/
public function __construct(Container $container)
{
$this->websocket = $container->make(Websocket::class);
}
/**
* 事件监听处理
*
* @return mixed
*/
public function handle($event)
{
//回复客户端消息
$this->websocket->emit(