http://wenda.workerman.net/?/question/508 這篇文章中,$inner_text_worker怎么知道$worker->onMessage里面的數(shù)據(jù)是否接收成功呢。意思就是$worker->onMessage已經(jīng)取到硬件返回的信息,那$inner_text_worker如何得到返回的值,而且$worker = new Worker('websocket://0.0.0.0:1234'); 和$inner_text_worker = new Worker('Text://0.0.0.0:5678');監(jiān)聽的是不同的端口,它們是異步通信的吧。
$worker->onWorkerStart = function($worker)
{
$inner_text_worker = new Worker('Text://0.0.0.0:5678');
$inner_text_worker->onMessage = function($connection, $buffer)use($worker)
{
global $worker;
$data = json_decode($buffer, true);
$uid = $data;
$buffer = $data;
$ret = sendMessageByUid($uid, $buffer);
// $connection->send($ret ? 'ok' : 'fail');
$connection->send($worker->data);//但發(fā)覺只能是第一次獲取到數(shù)據(jù),后面都是空的了。
};
$inner_text_worker->listen();
};
$worker->onConnect = function($connection)
{
echo "new connection from ip " . $connection->getRemoteIp() . "\n";
};
$worker->uidConnections = array();
$worker->onMessage = function($connection, $data)use($worker)
{
if(!isset($connection->uid))
{
$connection->uid = $data;
$worker->uidConnections = $connection;
return;
}
$worker->data = $data;//添加一個(gè)屬性
};
而且 $inner_text_worker = new Worker('Text://0.0.0.0:5678');第一次發(fā)送數(shù)據(jù)到$worker = new Worker('Text://0.0.0.0:1234');的時(shí)候$worker->data也是為空的,這樣也不符合要求。