123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Workerman;
- use App\Http\Controllers\IndexController;
- use App\Http\Controllers\TcpController;
- use \GatewayWorker\Lib\Gateway;
- use Illuminate\Support\Facades\Log;
- use Workerman\Worker;
- class Events
- {
- // businessWorker进程启动事件
- public static function onWorkerStart($businessWorker)
- {
- // 开启一个内部端口,方便内部系统推送数据,Text协议格式 文本+换行符
- }
- //连接事件
- public static function onConnect($client_id)
- {
- // 向当前client_id发送数据
- Gateway::sendToClient($client_id, "tcp ".$client_id);
- }
- //进程退出事件
- public static function onWebSocketConnect($client_id, $data)
- {
- }
- //消息事件
- public static function onMessage($client_id, $message)
- {
- Log::info($message);
- $index=new TcpController();
- $index->Accept($client_id,$message);
- }
- // 连接断开事件
- public static function onClose($client_id)
- {
- }
- function broadcast($message)
- {
- global $worker;
- // foreach($worker->uidConnections as $connection)
- //
- // {
- //
- // $connection->send($message);
- //
- // }
- Gateway::sendToAll($message);
- }
- }
|