Answer the question
In order to leave comments, you need to log in
How to use websocket in php to send message to specific user?
I use the Ratchet
library and with its help I can connect to the server and send messages, but only when the user has made a request. In order for the server to send a message when the server needs it, Ratchet uses ZMQ and WAMP . But the Ratchet documentation says how to use PubSub (subscribing to topics), and nothing about RPC.
How to send a message to a specific user without subscriptions?
Answer the question
In order to leave comments, you need to log in
It doesn't matter whether you use PubSub or RPC. These are two methods for solving the same problem. To send a message to a specific user, you just need to save the Connection in a convenient form by the onOpen event and then you can send messages to him either through the send method directly or through callResult/callError for WampConnection.
Raise the onCall event with a third party script like:
$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'pusher');
$socket->connect("tcp://localhost:5555");
$loop = React\EventLoop\Factory::create();
$loop->addPeriodicTimer(1, function() use ($socket){
$socket->send('notices');
});
$loop->run();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question