Php 如何在浏览器上运行ratchet的shell脚本,同时在cmd上运行talnet

Php 如何在浏览器上运行ratchet的shell脚本,同时在cmd上运行talnet,php,ratchet,Php,Ratchet,Telnet localhost 8080工作正常,但在这之后,当我在localhost上创建shell脚本时,它在firefox和chrome中显示错误,请参见下文 Firefox无法在ws://localhost:8080/上建立与服务器的连接。 require dirname(__DIR__) . '/vendor/autoload.php'; $server = IoServer::factory( new HttpServer( new WsSer

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

Firefox无法在ws://localhost:8080/上建立与服务器的连接。
   require dirname(__DIR__) . '/vendor/autoload.php';

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

   $server->run();'
var conn=newwebsocket('ws://localhost:8080')

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

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

   $server->run();'
这是我的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>

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

老兄,我今天为此挣扎了好几个小时,我希望这能帮助一些人

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

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

   $server->run();'
我的服务器设置: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

您是否使用其他websocket客户端进行过测试?我想如果你发布你的服务器代码会对我们有帮助。不,我没有使用其他代码,但我必须使用这个代码,我已经更新了我的问题。谢谢你的快速回复,现在请检查它并给我一些建议。我觉得一切都很好。firefox是否有可能使用代理?@Raj您是否从cmd终端启动服务器并保持其运行?比如进入命令提示符并进入项目目录,然后运行nin
php-bin/chat-server.php