实例化AsyncTcpConnection之后,在onMessage方法中调用并send数据,测试发现拿不到推送到服务端的数据,代码也没有报错,求大佬解惑
代码如下:
<?php
use Workerman\Worker;
use Workerman\Common\Auth;
use Workerman\Common\GetAboutParameter;
use Workerman\Common\GetPositionMessage;
use Workerman\Connection\AsyncTcpConnection;
require 'Autoloader.php';
require_once __DIR__ . '/vendor/autoload.php';
// 创建一个Worker监听8992端口,不使用任何应用层协议
$tcp_worker = new Worker("tcp://0.0.0.0:8992");
//以tcp协议连接远程tcp服务器
$tcp_connection = new AsyncTcpConnection("tcp://127.0.0.1:8000");
// 启动8个进程对外提供服务
$tcp_worker -> count = 8;
$tcp_worker -> onWorkerStart = function ($worker) {
};
// 当客户端发来数据时
$tcp_worker -> onMessage = function ($connection, $data) use (&$tcp_connection) {
$tcp_connection -> send($data);
};
// 运行worker
Worker ::runAll();
$tcp_worker->onMessage 回调中加上如下代码:
$tcp_connection->connect();
谢谢,加入$tcp_connection->connect(); 测试成功