【发布时间】:2015-12-18 20:31:06
【问题描述】:
我试图在 symfony2 应用程序上与 Elephant.io(Elephantio 捆绑包)和 Socket.io 进行实时聊天。
socket.io 服务器和我的 symfony 应用程序之间的连接运行良好,但是当我尝试将数据传递给 socket.io 时,它返回 [object Object]。
我就是这样做的:
#Config.yml
nc_elephant_io:
clients:
default:
connection: http://localhost:3006
version: 1.x
socketio_key:
connection: http://localhost:3000
version: 1.x
我的控制器
public function indexAction()
{
$client = $this->get('elephantio_client.socketio_key');
$elephantIOClient = $client->getElephantIO();
$elephantIOClient->initialize();
$elephantIOClient->emit('chat message', ['msg' => 'bar']);
$elephantIOClient->close();
return $this->render('default/index.html.twig');
}
我的 server.js
var io = require('socket.io').listen(3000);
io.on('connection', function(socket){
console.log('a user connected');
socket.on('chat message', function(msg){
console.log('message: ' + msg);
});
socket.on('disconnect', function(){
console.log('user disconnected');
});
});
当我刷新我的索引页面时,它会返回
连接的用户
但我的“味精”数据就在这里声明
$elephantIOClient->emit('聊天消息', ['msg' => 'bar']);
未渲染或未传递给socket.io并返回
连接的用户
消息:[对象对象]
用户断开连接
我已经阅读过有关此问题的主题,但从未阅读过关于 php/lephant.io 实现的文章。
是否有人已经遇到过这个问题,或者你也有一些想法来解决这个问题?
谢谢。
【问题讨论】: