zoukankan      html  css  js  c++  java
  • swoole推送信息一对一,一对多

    服务端

    $ws->on('message', function ($ws, $frame) {
        //echo "接收到的信息: {$frame->data}
    ";
        //$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."
    ";
        // 2.讲消息发送个所有客户端
        $arr = json_decode($content);
        $id = $arr[0];
        $str= $arr[1];
    
        //一对一推送
        $ws->push($id,$str);
        // 一对多,推送
        /*foreach ($ws->connections as $fd){
            //echo "FD:".$fd."
    ";
            $arr = json_decode($content);
            $id = $arr[0];
            $str= $arr[1];
            $ws->push($fd,$str);
        }*/
    });
  • 相关阅读:
    c++ 容器学习 理论
    TCP和UDP发送数据包的大小问题
    key.go
    election.go
    watch.go
    txn.go
    sort.go
    retry.go
    op.go
    maintenance.go
  • 原文地址:https://www.cnblogs.com/wesky/p/10525001.html
Copyright © 2011-2022 走看看