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');
这是我的外壳脚本
<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.please help上运行棘轮shell脚本!
伙计,我今天为此挣扎了几个小时,我希望这能帮助到别人。
我的服务器设置: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