Events.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Workerman;
  3. use App\Http\Controllers\IndexController;
  4. use App\Http\Controllers\TcpController;
  5. use \GatewayWorker\Lib\Gateway;
  6. use Illuminate\Support\Facades\Log;
  7. use Workerman\Worker;
  8. class Events
  9. {
  10. // businessWorker进程启动事件
  11. public static function onWorkerStart($businessWorker)
  12. {
  13. // 开启一个内部端口,方便内部系统推送数据,Text协议格式 文本+换行符
  14. }
  15. //连接事件
  16. public static function onConnect($client_id)
  17. {
  18. // 向当前client_id发送数据
  19. Gateway::sendToClient($client_id, "tcp ".$client_id);
  20. }
  21. //进程退出事件
  22. public static function onWebSocketConnect($client_id, $data)
  23. {
  24. }
  25. //消息事件
  26. public static function onMessage($client_id, $message)
  27. {
  28. Log::info($message);
  29. $index=new TcpController();
  30. $index->Accept($client_id,$message);
  31. }
  32. // 连接断开事件
  33. public static function onClose($client_id)
  34. {
  35. }
  36. function broadcast($message)
  37. {
  38. global $worker;
  39. // foreach($worker->uidConnections as $connection)
  40. //
  41. // {
  42. //
  43. // $connection->send($message);
  44. //
  45. // }
  46. Gateway::sendToAll($message);
  47. }
  48. }