T
T
TANK_IST2013-11-25 01:06:38
PHP
TANK_IST, 2013-11-25 01:06:38

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

2 answer(s)
Z
zloyusr, 2013-11-25
@TANK_IST

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.

F
frei3000, 2013-11-25
@frei3000

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();

You can keep the script alive, for example, with a supervisor

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question