2015-12-15 141 views
0

我一直在阅读很多,仍然挣扎让这个棘轮工作。我努力让服务器端shell脚本启动并运行。供应商目录已从原始安装位置移动,但完全移动。当我运行php composer.phar更新或安装,每次都说没有更新或安装。棘轮Websockets - 滴注问题

这里是我的目录结构:

/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的致命错误的错误:类 '棘轮\ CommApp' 不/var/www/bin/socket.php找到第28行

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(); 
    } 
} 

回答

0

我不我是如何解决它,但我重新安装了一切,它的工作。我认为这与安装棘轮的初始位置有关,但我无法确定。