Last active
August 29, 2024 05:33
-
-
Save cboden/3119135 to your computer and use it in GitHub Desktop.
Ratchet Routing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) { | |
} | |
} |
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
Does the App class of the ratchet not work anymore in version 0.4.4?