dsvjw20866 2013-08-11 13:59
浏览 49

在C:\ wamp \ www \ bin \ chat-server.php中找不到“MyChat \ Chat”类

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})
";
    }
    function onClose(ConnectionInterface $conn)
    {
        echo "Connection closed: {$conn->resourceId} 
";
        $this->clients->detach($conn);
    }
    function onError(ConnectionInterface $conn, \Exception $e)
    {
        echo "An error has occured: {$e->getMessage()}. Closing connection... 
";
        $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.

  • 写回答

1条回答 默认 最新

  • doujia6503 2013-09-06 18:19
    关注

    This is a little late but it looks like you are using composer, so you may need to run that installer?

    From your directory try running each of these and see if that helps:

    ./composer.phar install --dev
    ./composer.phar update
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式