webman控制器调用ws客户端,发送数据是正确的,接收服务器数据每次接收的是2次数据

lianggan
<?php
namespace app\controller;
use support\Request;
use Workerman\Connection\AsyncTcpConnection;
class Cabinet
{   

    //  
    public function __construct()
    {
       global  $con;
       global  $cmdindex;
       $con = new AsyncTcpConnection('tcp://127.0.0.1:8282');
       $con->onConnect = function(AsyncTcpConnection $con) {
         //$con->send('hello');
       };

       $con->onMessage = function(AsyncTcpConnection $con, $data) {
         //双倍接收 
         echo $data;
         //$con->send($data);
       };

       $con->connect();
    }

    //
    public function hello(Request $request)
    {
        global  $con;
        $default_name = 'webman';
1171 1 0
1个回答

walkor 打赏

__construct() 里打印下看下执行几次,如果你是开了2个进程,每个进程初始化1次,总共会有2个con连接是正常的。

  • 暂无评论
年代过于久远,无法发表回答
×
🔝