I am trying to implement the basic chat application from http://socketo.me/docs/hello-world, however I keep getting this error. I tried to move files around, but with no success, but I am quite sure that I don't put the files in the right place. I'm completly new to composer and websockets and psr-0 and I still have a lot to learn about PHP. Here are my path tree and my sources:
C:\wamp\www\
bin
chat-server.php
src
MyChat
Chat.php
vendor
{dependencies}+autoload.php
composer.json
composer.phar
composer.lock
Chat.php
<?php
namespace MyChat;
require dirname(__DIR__) . '\vendor\autoload.php';
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Chat implements MessageComponentInterface
{
protected $clients;
function __construct()
{
$this->clients=new \SplObjectStorage();
}
function onOpen(ConnectionInterface $conn)
{
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})\n";
}
function onClose(ConnectionInterface $conn)
{
echo "Connection closed: {$conn->resourceId} \n";
$this->clients->detach($conn);
}
function onError(ConnectionInterface $conn, \Exception $e)
{
echo "An error has occured: {$e->getMessage()}. Closing connection... \n";
$conn->close();
}
function onMessage(ConnectionInterface $from, $msg)
{
$receivers=count($this->clients)-1;
foreach($this->clients as $client)
{
if($client!=$from)
{
$client->send($msg);
}
}
}
}
chat-server.php
<?php
require dirname(__DIR__) . '\vendor\autoload.php';
use Ratchet\Server\IoServer;
use MyChat\Chat;
$server= IoServer::factory (new Chat() ,8080,'0.0.0.0');//0.0.0.0 is default, means accept all connections
$server->run();
composer.json
{
"require": {
"cboden/Ratchet": "0.2.*"
},
"autoload": {
"psr-0": {
"MyChat": "src"
}
}
}
My php.exe is in C:\wamp\bin\php\php5.4.12 . I would be really thankful for a suggestion, I can't really spot where am I mistaken.