Ratchet Server未运行

时间:2018-06-03 23:01:14

标签: php sockets websocket ratchet ratchet-2

我已成功安装Ratchet套接字库。我正在通过终端运行该文件,但终端上没有打印任何内容。我不知道我在这里做错了什么。这是代码

require 'vendor/autoload.php';

use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

    // Make sure composer dependencies have been installed
   // require __DIR__ . '/vendor/autoload.php';

/**
 * chat.php
 * Send any incoming messages to all connected clients (except sender)
 */
class MyChat implements MessageComponentInterface {
    protected $clients;

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

    public function onOpen(ConnectionInterface $conn) {
          echo 'Connection Established', "\n";
        $this->clients->attach($conn);
    }

    public function onMessage(ConnectionInterface $from, $msg) {

          echo 'Received "', $msg, '"', "\n";
        /*foreach ($this->clients as $client) {
            if ($from != $client) {
                $client->send($msg);
            }
        }*/
    }

    public function onClose(ConnectionInterface $conn) {
        $this->clients->detach($conn);
    }

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

    // Run the server application through the WebSocket protocol on port 8080
    $app = new Ratchet\App('172.xx', 8154);
   $app->route('/chat', new MyChat);
    $app->route('/echo', new Ratchet\Server\EchoServer, array('*'));
   $app->run();

?>

'建立连接'没有打印出来,也没有$ msg。我在这里缺少什么

0 个答案:

没有答案