WebSocketServerCommand.php
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?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();
}
}