我正在尝试使用此捆绑包通过节点控制器 symfony https://github.com/bazo/tembo进行调用
但我必须添加例外以供使用
我想在我的节点中调用我的函数“barno”
节点.js
var app = require('express')()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server);
server.listen(9001);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.emit('news2', { hello: 'world2' });
socket.on('message', function(data){
socket.broadcast.emit('broadcast-action', data);
});
socket.on('barno', function(data) {
console.dir(data);
socket.emit('barno', {profilo_da_seguire: '100'});
});
});
我的控制器
$client = new SocketIOClient('http://localhost:9001');
$client->connect();
//emit event
$args = ['nome' => 'alessio'];
$client->emit('barno', $args);
$received = 'barno';
$pippo = array();
try {
$client->listen(function($event, Message $message = null) use (&$received, &$pippo) {
if($message !== null) {
if ($message->getName() == $received) {
$gino = $message->getArgs();
if (!is_object($gino[0])) {
$args = json_decode(current($message->getArgs()));
}else{
$args = $message->getArgs();
$pippo[] = $args[0];
}
throw new \Exception('Load');
}
/*$message = sprintf('packet: %d, time: %f, heartbeats: %d', $args->packet, $args->time, $args->heartbeats);
writeDebug($message);*/
}
});
} catch (\RuntimeException $e) {
echo $e->getMessage();
} catch (\Exception $e) {
}
//var_dump($pippo);
foreach ($pippo as $i => $pluto) {
$pippo[$i]->nome= 'barno';
}
$client->disconnect(1);
return array(
'pippo' => $pippo
);
}
当代码到达这里时,我看到了 Xdebug
if ($message->getName() == $received)
我有这些电话
$message->getName() = "news"
$message->getName() = "news2"
$message->getName() = "barno"
我只想调用函数 Barno,我该怎么做?
比我加这个
throw new \Exception('Load');
因为循环中输入的代码
结果是
array (size=1)
0 =>
object(stdClass)[53]
public 'profilo_da_seguire' => string '100' (length=3)
public 'nome' => string 'barno' (length=5)
这是正确的,但在除非调用之后