服务端

$ws->on('message', function ($ws, $frame) {
    //echo "接收到的信息: {$frame->data}\n";
    //$ws->push($frame->fd, "server: {$frame->data}");
    //echo "服务器已接收:【".$frame->fd."】";
    //$ws->push($frame->fd, json_encode(['hello','world'.$frame->data]));


    // 1.客户端发送过来的信息
    $content = $frame->data;
    echo "服务器接收到信息:".$content."\n";
    // 2.讲消息发送个所有客户端
    $arr = json_decode($content);
    $id = $arr[0];
    $str= $arr[1];

    //一对一推送
    $ws->push($id,$str);
    // 一对多,推送
    /*foreach ($ws->connections as $fd){
        //echo "FD:".$fd."\n";
        $arr = json_decode($content);
        $id = $arr[0];
        $str= $arr[1];
        $ws->push($fd,$str);
    }*/
});

 

相关文章:

  • 2021-11-19
  • 2021-06-26
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-09-24
猜你喜欢
  • 2022-01-31
  • 2021-08-27
  • 2022-12-23
  • 2021-12-21
  • 2021-06-11
  • 2021-05-25
相关资源
相似解决方案