棘轮腹板 - 滴注问题

时间:2015-12-15 01:08:12

标签: websocket installation ratchet

我一直在阅读很多,但仍在努力让这个棘轮起作用。我正在努力让服务器端shell脚本启动并运行。供应商目录已从其原始安装位置移开,但它已完全移动。当我运行php composer.phar更新或安装时,每次都没有说更新或安装。

这是我的目录结构:

/var/www/bin/socket.php (server script)
        /src/CommApp/Comm.php
        /htmp/ (public site)
        /vendor/
        composer.json
        composer.phar

composer.json

{
"autoload": {
    "psr-0": {
        "CommApp": "src"
    }
},
"require": {
    "cboden/ratchet": "0.3.*"
}

}

当我尝试顶级版本的服务器代码时,它可以工作,但我无法弄清楚如何绑定到不同的IP,而不是127.0.0.1我需要绑定到0.0.0.0。所以我在底部发现了这个新版本的代码,它允许我绑定到我需要的ip。 buttom代码给了我一个错误 PHP致命错误:第28行的/var/www/bin/socket.php中找不到类'Ratchet \ CommApp'

socket.php

<?php
/**
require __DIR__ . '/../vendor/autoload.php';

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use CommApp\Comm;

$server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new Comm()
        )
    ),
    8080
);

$server->run();
 */

 // Ratchet/0.3
$app = new Ratchet\App('www.mysite.com',8080,'0.0.0.0');
$app->route('/CommApp',new Comm);
$app->run();

以下是 Comm.php

的代码
<?php

namespace CommApp;

use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class Comm implements MessageComponentInterface
{

    protected $clients;

    public function __construct() {
        $this->clients = new \SplObjectStorage;
    }

    public function onOpen(ConnectionInterface $conn) {
        //store the new connection
        $this->clients->attach($conn);

        echo "someone connected\n";
    }

    public function onMessage(ConnectionInterface $from, $msg) {
        //send the message to all the other clients except the one who sent.
        foreach ($this->clients as $client) {
            if ($from !== $client) {
                $client->send($msg);
            }
        }
    }

    public function onClose(ConnectionInterface $conn) {
        $this->clients->detach($conn);
        echo "someone has disconnected";
    }

    public function onError(ConnectionInterface $conn, \Exception $e) {
        echo "An error has occurred: {$e->getMessage()}\n";
        $conn->close();
    }
}

1 个答案:

答案 0 :(得分:0)

我不知道我是如何修复它但是我重新安装了一切并且它有效。我认为这与Ratchet安装的初始位置有关,但我无法确定。