-
Apologies if this was already discussed and answered elsewhere. I've searched all other rr2 related packages and plugins for answers but couldn't find one. I'm trying to implement websockets in my application. Based on all other discussions, it seems as though they should be working, but no matter what i attempt (based on the examples in the various plugins repos), all i ever get is a Start command:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Hey @M-Porter 👋🏻 , nice to meet you :) Have you tried to use tools like Postman to connect? |
Beta Was this translation helpful? Give feedback.
-
Per @rustatian
Add a new route to <?php
// routes/web.php
// The route here should be same as defined in your .rr.yaml file. https://github.com/roadrunner-server/roadrunner/blob/4d8552df9fb578a2a4d3a541547f91e205661a9d/.rr.yaml#L879
Route::get('/ws', fn () => new \GuzzleHttp\Psr7\Response()); You can now connect to the Websocket with ws = new WebSocket('ws://localhost:8000/ws'); and send a message from the server with $broadcast = new Broadcast(RPC::create('tcp://127.0.0.1:6001'));
$broadcast->publish(['topic-1', 'topic-2'], 'message from broker');
$topic = $broadcast->join(['topic-1', 'topic-2']);
$topic->publish('message from topic');
$topic->publish(['message 1 from topic', 'message 2 from topic']); |
Beta Was this translation helpful? Give feedback.
Per @rustatian
Add a new route to
/ws
in yourroutes/web.php
and return a valid PSR7 response (MUST BE PSR7!!!!).You can now connect to the Websocket with
and send a message from the se…