2017-04-25 11 views
0

マイWebSocketのファイル:ラチェットPHPのWebSocket永続Ubuntuの16.04

<?php 
require __DIR__ . '/../../../vendor/autoload.php'; 

use Ratchet\MessageComponentInterface; 
use Ratchet\ConnectionInterface; 

require 'chat.php'; 

// Run the server application through the WebSocket protocol on port 8080 
$app = new Ratchet\App("localhost", 8080, '0.0.0.0', $loop); 
$app->route('/chat', new Chat, array('*')); 

$app->run(); 

私はセットアップ私のWebSocketについては、このガイドに従っ: https://blog.samuel.ninja/the-tutorial-for-php-websockets-that-i-wish-had-existed/

ローカルそれはphp socket.phpを使用して動作します(ウィンドウ10上のXAMPPでテスト済み) 。 私は私の仮想マシン(Ubuntuの16.04)上で展開しようとすると、私はこのエラーを持っている:

WebSocket connection to 'ws://localhost:8080/chat?id=NDY=&group=43,60' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED 

PS:私はまた、代わりにサービスとそれを起動する必要がありphp /var/www/path-to-websocket/socket.php

を使用してのWebSocketを起動しようとしていますコマンドラインの、しかし説明した方法は動作しません

答えて

0

代わりにSERVERNAME localhostを使用してください。

PHP RATCHETから:

Run your website and WebSocket server on the same machine using port 8080 for WebSockets and take the chance client proxies won't block traffic 
Run your WebSocket server on its own server on port 80 under a subdomain (sock.example.com) 
Put a reverse proxy (HAProxy or Varnish) in front of your webserver and WebSocket server 

ソース:http://socketo.me/docs/deploy