workman AsyncTcpConnection 获取返回message 返回出现问题

suplax

问题描述

用workman 的AsyncTcpConnection 异步访问外部wss端口,获取的message 返回出现问题

为此你搜索到了哪些方案及不适用的原因

远程socket握手成功

Error: Call to a member function send() on null in /www/wwwroot/streaming.zznet.live/startwork.php:36
Stack trace:
#0 /www/wwwroot/streaming.zznet.live/vendor/workerman/workerman/Connection/TcpConnection.php(646): {closure}()
#1 [internal function]: Workerman\Connection\TcpConnection->baseRead()
#2 /www/wwwroot/streaming.zznet.live/vendor/workerman/workerman/Events/Event.php(193): EventBase->loop()
#3 /www/wwwroot/streaming.zznet.live/vendor/workerman/workerman/Worker.php(1638): Workerman\Events\Event->loop()
#4 /www/wwwroot/streaming.zznet.live/vendor/workerman/workerman/Worker.php(1429): Workerman\Worker::forkOneWorkerForLinux()
#5 /www/wwwroot/streaming.zznet.live/vendor/workerman/workerman/Worker.php(1403): Workerman\Worker::forkWorkersForLinux()
#6 /www/wwwroot/streaming.zznet.live/vendor/workerman/workerman/Worker.php(560): Workerman\Worker::forkWorkers()
#7 /www/wwwroot/streaming.zznet.live/startwork.php(45): Workerman\Worker::runAll()

下面是代码

$ws_worker = new Worker("websocket://0.0.0.0:2346");

// 启动4个进程对外提供服务
$ws_worker->count = 6;

// 当收到客户端发来的数据后返回hello $data给客户端
$ws_worker->onMessage = function(TcpConnection $connection, $data) {
    $context_option = array(
        'socket' => array(
            // ip必须是本机网卡ip,并且能访问对方主机,否则无效
            'bindto' => '202.**.**.192:2346',
        )
    );

    // 发起异步连接
    $con = new AsyncTcpConnection('ws://*******', $context_option);

    // 设置以ssl加密方式访问
    $con->transport = 'ssl';

    $con->onConnect = function(AsyncTcpConnection $con) {
        echo "远程socket握手成功\n";
        $str = 'hello';
        $con->send($str);
    };

    $con->onMessage = function(AsyncTcpConnection $con, $result) {
        $connection->send($result , true);
    };

    $con->connect();
};
360 1 0
1个回答

walkor 打赏

截图

报错里文件及行数都有,看一眼就直到了呀,$connection未定义

  • 暂无评论
×
🔝