WebSocketServerCommand.php 1.5 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 自定义命令: 自定义API接口,创建api接口的全部类:控制层、服务层、数据验证层、数据转换层、模型层
 *            命令:php artisan make:api User (这个是路由的单数,如果是多个单词要用驼峰写法UserRole)
 * 参数说明:
 * --title:该模块的名称
 * --author:作者
 * --policy:是否创建 policy 策略类
 * --request:是否创建 request 验证类
 * --admin:是否创建 laravel-admin 管理端的类
 * ...
 * ...
 * ...
 *
+-----------------------------------------------------------------------------------------------------------------------
 *
 * @copyright   Copyright
 * @author      Richer
 * @package     App\Console\Commands
 * @version     2019年11月27日,11:30:36
 * @link
 */
namespace App\Console\Commands;

use App\Services\ChatServer;
use Illuminate\Console\Command;
use Illuminate\Console\GeneratorCommand;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Ratchet\Server\IoServer;

class WebSocketServerCommand extends Command
{
    protected $signature = 'websocket:serve';

    protected $description = 'Start the WebSocket server';

    public function handle()
    {
        $server = IoServer::factory(
            new HttpServer(
                new WsServer(
                    new ChatServer()
                )
            ),
            8080
        );

        $server->run();
    }
}