棘轮网络插座-煽动问题



我读了很多书,仍然在努力让这个棘轮工作。我正在努力让服务器端的shell脚本启动并运行。供应商目录已从其原始安装位置移动,但已整体移动。当我运行phpcomposer.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 RatchetServerIoServer;
use RatchetHttpHttpServer;
use RatchetWebSocketWsServer;
use CommAppComm;
$server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new Comm()
        )
    ),
    8080
);
$server->run();
 */
 // Ratchet/0.3
$app = new RatchetApp('www.mysite.com',8080,'0.0.0.0');
$app->route('/CommApp',new Comm);
$app->run();

这是Comm.php的代码

<?php
namespace CommApp;
use RatchetMessageComponentInterface;
use RatchetConnectionInterface;
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 connectedn";
    }
    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();
    }
}

我不知道我是如何修复它的,但我重新安装了所有东西,它正常工作。我认为这与安装棘轮的最初位置有关,但我不能确定。

相关内容

  • 没有找到相关文章

最新更新