【问题标题】:Ratchet Websockets - Instillation problemsRatchet Websockets - 灌输问题
【发布时间】:2015-12-15 01:08:12
【问题描述】:

我读了很多书,但仍在努力让这个棘轮工作。我正在努力让服务器端 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。按钮代码给了我一个错误 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();
    }
}

【问题讨论】:

    标签: websocket installation ratchet


    【解决方案1】:

    我不知道如何修复它,但我重新安装了所有内容并且它工作正常。我认为这与安装 Ratchet 的初始位置有关,但我不能确定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多