Skip to content

Instantly share code, notes, and snippets.

@cboden
Last active August 29, 2024 05:33
Show Gist options
  • Save cboden/3119135 to your computer and use it in GitHub Desktop.
Save cboden/3119135 to your computer and use it in GitHub Desktop.
Ratchet Routing
<?php
$collection = new RouteCollection;
$collection->add('chatRoom', new Route('/demo', array(
'_controller' => new ChatRoom
, 'allowedOrigins' => 'socketo.me'
)));
$collection->add('echo', new Route('/echo', array(
'_controller' => new AbFuzzyServer
, 'allowedOrigins' => '*'
)));
$collection->add('uhOh', new Route('/what/{happens}/{now}', array(
'_controller' => new Trouble
)));
$router = new WsRouter;
$router->addCollection($collection);
$wsserv = new WebSocket($router);
$server = new IoServer($wsserv);
$server->run();
<?php
use Ratchet\ConnectionInterface;
use Ratchet\MessageComponentInterface;
class Trouble implements MessageComponentInterface {
public function onOpen(ConnectionInterface $conn, , $happens = '', $now = '') { // ???
$from->send('Welcome to ' . $from->WebSocket->Router->path);
}
public function onMessage(ConnectionInterface $from) {
}
public function onClose(ConnectionInterface $conn) {
}
public function onError(ConnectionInterface $conn, \Exception $e) {
}
}
@md-riaz
Copy link

md-riaz commented Feb 11, 2024

Does the App class of the ratchet not work anymore in version 0.4.4?

@TodoshiTakato
Copy link

Here is a working example for Laravel. My current version is 0.4.2.

https://gist.github.com/rahulhaque/2a92380e54779d03660e01da3851d24d

Thank you man, searched all internet for a week!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment