I'm using Symfony2 to build a simple chat application. I decided to use the GeniusesOfSymfony/WebSocketBundle for my WebSocket, which is powered by Ratchet :
https://github.com/GeniusesOfSymfony/WebSocketBundle
I managed to get the chat working using PubSub, but I want to use the push integration instead: I want the client to send the message via AJAX to my Symfony2 controller, which in turn should push the message to all clients of the WebSocket.
I followed this documentation page:
https://github.com/GeniusesOfSymfony/WebSocketBundle/blob/master/Resources/docs/Pusher.md
I've tried using both ZMQ and Websocket Pusher.
With ZMQ, when I run the websocket, I get the cmd notification:
ZMQ transport listening on 127.0.0.1:5555
However, pushing messages doesn't work:
$pusher = $this->container->get("gos_web_socket.zmq.pusher");
//push(data, route_name, route_arguments)
$pusher->push(["type" => "newMessage", "text" => $request->request->get("msg")], "chat_topic");
This is the onPush method in my ChatTopic class:
class ChatTopic implements TopicInterface, PushableTopicInterface {
public function onPush(Topic $topic, WampRequest $request, $data, $provider) {
$topic->broadcast($data);
}
}
The onPush method never gets called. Also, the pusher events never get fired. There doesn't appear to be an exception in the code.
With WebSocket Pusher, I'm not even able to get the service running. There is no notification in the cmd like with ZMQ, and using netstat
command I was not able to detect that it's listening on port 1337. When I try to push to it, I get the exception :
Could not open socket. Reason: No connection could be made because the target machine actively refused it
Probably because there is no service listening on port 1337.
P.S. - I am on Windows 10 and using WAMP server. I've successfully installed the ZMQ extension on WAMP, as indicated in the phpinfo()
.
php app/console gos:websocket:server --host 0.0.0.0
. You must get something like this - joxi.ru/D2P0vdvcEvW823. And then try to push something. You must get something like this: joxi.ru/82QNvLviNK3QAd – Satire