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 脚本。请帮助!