EventsTCP.php 1.2 KB

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