作者 lyh

gx

@@ -27,3 +27,13 @@ Websocket::on('example', function ($websocket, $data) { @@ -27,3 +27,13 @@ Websocket::on('example', function ($websocket, $data) {
27 @file_put_contents(storage_path('logs/lyh_error.log'), var_export(3333, true) . PHP_EOL, FILE_APPEND); 27 @file_put_contents(storage_path('logs/lyh_error.log'), var_export(3333, true) . PHP_EOL, FILE_APPEND);
28 $websocket->emit('message', $data); 28 $websocket->emit('message', $data);
29 }); 29 });
  30 +
  31 +Websocket::on('message', function ($websocket, $data) {
  32 + // 处理接收到消息时的逻辑
  33 +
  34 + // 假设 $data 是客户端发送过来的数据
  35 + // 在这里您可以根据接收到的消息进行处理
  36 +
  37 + // 回复消息给客户端
  38 + $websocket->send("Hello, Client! You sent: $data");
  39 +});