0

Telnet localhost 8080 工作正常,但之后当我在 localhost 上创建 shell 脚本时,它在 firefox 和 chrome 中显示错误,见下文

Firefox can't establish a connection to the server at ws://localhost:8080/. var conn = new WebSocket('ws://localhost:8080');

这是我的shell脚本

   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
   </script>
   <script>
   jQuery(document).ready(function(){
     var conn = new WebSocket('ws://localhost:8080');
    conn.onopen = function(e) {
     console.log("Connection established!");
    };

   conn.onmessage = function(e) {
    console.log(e.data);
     };
     });
   </script>

这是我的chat-server.php 代码'

   require dirname(__DIR__) . '/vendor/autoload.php';

   $server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new Chat()
        )
    ),
    8080
    );

   $server->run();'

shell 脚本保存在根目录的 info.php 中,chat-server.php 保存在 root/bin/ 目录中,但总是显示相同的错误,我不知道如何在 localhost 上运行棘轮 shell 脚本。请帮助!

4

1 回答 1

0

伙计,我今天为此苦苦挣扎了几个小时,我希望这对某人有所帮助。

我的服务器设置:Ubuntu 14.04 上的 Apache/2.4.18。

var conn = new WebSocket('ws://xxx.xxxx.xxx:8888');

错误:

失败:WebSocket 打开握手超时。

我最终没有正确配置端口并且需要运行:

iptables -I INPUT 1 -i eth0 -p tcp --dport 8888 -j ACCEPT
于 2016-08-31T20:06:55.337 回答