PHPフレームワークを使ったWebアプリケーションでwebsocketがつながらず困っております。
環境は以下の通りです。
Apache 2.4
PHP 5.4
PHPフレームワーク codeigniter3
・rachetをcomposerを使用しインストール済み
・websocket通信用に8080番ポート解放済み
・SSL環境
ratchet(http://socketo.me/)を使用して、チャット機能を実装したいのですが、ブラウザのコンソールに以下のメッセージが出力されます。
「WebSocket connection to 'wss://xxxx.jp:8080' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET」
なおサーバ側のPHPとクライアントのjavascriptは以下の通りです
【サーバ側】
<?php use Ratchet\MessageComponentInterface; use Ratchet\ConnectionInterface; use Ratchet\Server\IoServer; use Ratchet\WebSocket\WsServer; use Ratchet\Http\HttpServer; require dirname(__FILE__) . '/../third_party/ratchet/autoload.php'; /** * websocket.php * Send any incoming messages to all connected clients (except sender) */ class Chat implements MessageComponentInterface { public $is_skip_auth_check = true; protected $clients; public function __construct() { $this->clients = new \SplObjectStorage; } public function onOpen(ConnectionInterface $conn) { $this->clients->attach($conn); } public function onMessage(ConnectionInterface $from, $msg) { 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) { $conn->close(); } } // Run the server application through the WebSocket protocol on port 8080 //server = IoServer::factory(new WsServer(new Chat), 8080); $server = new Ratchet\App('xxxxx.jp', 8080); $server->route('/chat', new Chat); $server->route('/echo', new Ratchet\Server\EchoServer, array('*')); $server->run(); --------------------------------------------------------- 【javascript】 --------------------------------------------------------- var conn = new WebSocket('wss://xxxx:8080/Chat/'); conn.onopen = function(e) { console.log("Connection established!"); }; conn.onmessage = function(e) { console.log(e.data); }; function send() { var msg = document.getElementById("text").value; conn.send(msg); } ---------------------------------------------------------回答1件
あなたの回答
tips
プレビュー