質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
WebSocket

WebSocketとは双方向・全二重コミュニケーションのためのAPIでありプロトコルのことを指します。WebSocketはHTML5に密接に結びついており、多くのウェブブラウザの最新版に導入されています。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

0回答

602閲覧

ratchetをしようしてwebsocketサーバーを構築する時にエラーが出る

msssss

総合スコア64

WebSocket

WebSocketとは双方向・全二重コミュニケーションのためのAPIでありプロトコルのことを指します。WebSocketはHTML5に密接に結びついており、多くのウェブブラウザの最新版に導入されています。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

1クリップ

投稿2019/05/06 13:09

編集2019/05/06 13:10

json

1コード 2{ 3 "autoload": { 4 "psr-0": { 5 "MyApp": "src" 6 } 7 }, 8 "require": { 9 "cboden/ratchet": "*" 10 } 11}

php

1 2コード 3 4<?php 5use Ratchet\Server\IoServer; 6use MyApp\Chat; 7 8 require dirname(__DIR__) . '/vendor/autoload.php'; 9 10 $server = IoServer::factory( 11 new Chat(), 12 8080 13 ); 14 15 $server->run();

php

1コード 2<?php 3namespace MyApp; 4use Ratchet\MessageComponentInterface; 5use Ratchet\ConnectionInterface; 6 7class Chat implements MessageComponentInterface { 8 protected $clients; 9 10 public function __construct() { 11 $this->clients = new \SplObjectStorage; 12 } 13 14 public function onOpen(ConnectionInterface $conn) { 15 // Store the new connection to send messages to later 16 $this->clients->attach($conn); 17 18 echo "New connection! ({$conn->resourceId})\n"; 19 } 20 21 public function onMessage(ConnectionInterface $from, $msg) { 22 $numRecv = count($this->clients) - 1; 23 echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n" 24 , $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's'); 25 26 foreach ($this->clients as $client) { 27 if ($from !== $client) { 28 // The sender is not the receiver, send to each client connected 29 $client->send($msg); 30 } 31 } 32 } 33 34 public function onClose(ConnectionInterface $conn) { 35 // The connection is closed, remove it, as we can no longer send it messages 36 $this->clients->detach($conn); 37 38 echo "Connection {$conn->resourceId} has disconnected\n"; 39 } 40 41 public function onError(ConnectionInterface $conn, \Exception $e) { 42 echo "An error has occurred: {$e->getMessage()}\n"; 43 44 $conn->close(); 45 } 46} 47

上記のコードでwebsocketのさーばーを構築しようとしたのですが、エラーが出ます。

chat-server.phpでは
Warning: require(C:\xampp\htdocs\test/vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\test\bin\chat-server.php on line 5

Fatal error: require(): Failed opening required 'C:\xampp\htdocs\test/vendor/autoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\test\bin\chat-server.php on line 5

Chat.phpでは
Fatal error: Interface 'Ratchet\MessageComponentInterface' not found in C:\xampp\htdocs\test\src\MyApp\Chat.php on line 6

のように表示されます。
どのように改善すればよいですか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問