Jump to content

how to rectify [PHP Fatal error: Interface 'Ratchet\MessageComponentInterface' not found ] in ratchet


Recommended Posts

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.
 
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.