shan2batman Posted December 20, 2015 Share Posted December 20, 2015 I'm trying to create a basic websocket chat from a tutorial in YouTube and I'am facing this error in the terminal when i run > php bin/server.php Fatal error:** Interface 'Ratchet\MessageComponentInterface' not found in /var/www/html/websocket/bin/chat.php on line 6 My code is as follows for chat.php:- <?php namespace MyApp; use Ratchet\MessageComponentInterface; use Ratchet\ConnectionInterface; class chat implements MessageComponentInterface { protected $clients; public function __construct() { $this->clients=new \SplObjectStorage; } public function onOpen(ConnectionInterface $conn) { $this->clients->attach($conn); } public function onClose(ConnectionInterface $conn) { $this->clients->detach($conn); } public function onMessage(ConnectionInterface $conn,$msg) { foreach($this->clients as $client){ if($client !==$conn){ $client->send($msg); } } } public function onError(ConnectionInterface $conn, \Exception $e) { echo "the following error occured: ".$e->getMessage(); $conn->close(); } } code for server.php:- <?php require 'chat.php'; require __DIR__ .'/vendor/autoload.php'; use Ratchet\Server\IoServer; use Ratchet\Http\HttpServer; use Ratchet\WebSocket\WsServer; $server=IoServer::factory(new HttpServer(new WsServer (new chat())) , 8080); $server->run(); Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.