简体   繁体   English

PHP的socket.io与symfony

[英]php socket.io with symfony

I have a symfony project where I want to use websockets. 我有一个symfony项目,我想在其中使用websockets。 This is actually a project to provide mobile application with apis. 这实际上是一个为移动应用程序提供api的项目。 From mobile(IOS,Android) there must be request with post data to server(for example /mobile/ => goes to symfony ClientController -> indexAction) where I need to run the socket, open channel and send message, and on mobile application will also used socket.io to detect messages from socket channel. 从移动设备(IOS,Android),必须有带数据的请求到服务器(例如,/ mobile / =>转到symfony ClientController-> indexAction),在此我需要运行套接字,打开通道并发送消息,并在移动应用程序上还将使用socket.io来检测来自套接字通道的消息。

Is there a way to use socket.io in symfony? 有没有办法在symfony中使用socket.io?

I have installed Ratchet it seams working ok, but in all examples I found connection and message sending was done with client side, with JS, 我已经安装了Ratchet,它的接缝工作正常,但是在所有示例中,我发现连接和消息发送都是通过客户端,JS完成的,

var conn = new WebSocket('ws://localhost:8080');
conn.onopen = function(e) {
    console.log("Connection established!");
};

conn.onmessage = function(e) {
    console.log(e.data);
};

I don't need client side, It is planning that server will run the socket, open new channel and send message through it. 我不需要客户端,它正在计划服务器将运行套接字,打开新通道并通过它发送消息。 Something like it is done with nodeJS and socket.io (using - broadcast, emit, on, functions) 类似的事情是通过nodeJS和socket.io完成的(使用-广播,发射,打开,功能)

The best tool for the job seems to be this bundle: https://github.com/GeniusesOfSymfony/WebSocketBundle . 最好的工具似乎是这个捆绑包: https : //github.com/GeniusesOfSymfony/WebSocketBundle You probably need a PHP Websocket server that you start and configure with the above bundle. 您可能需要启动并使用上述捆绑软件配置的PHP Websocket服务器。

If I understood correctly, the mobile applications (iOS, Android) will be the clients. 如果我理解正确,那么移动应用程序(iOS,Android)将是客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM