我正在开发一个带有棘轮的 websocket,当我尝试连接它时,几分钟后它只在控制台中打印“WebSocket connection to 'ws://127.0.0.1:8888/' failed: WebSocket opening handshake timed out”,但在外壳打印中:
New connection! (48)
Connection 48 sending message "GET / HTTP/1.1
Host: localhost:8888
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: */*
Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
Origin: http://socketo.me
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Key: kMUmcl5+slye1dy0ISFOtQ==
DNT: 1
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
" to 0 other connections
服务器代码:
<?php
use Ratchet\Server\IoServer;
use MyApp\Chat;
require dirname(__DIR__) . '/vendor/autoload.php';
$server = IoServer::factory(
new Chat(),
8888
);
$server->run();
?>
客户端代码:
<!DOCTYPE html>
<script>
const conn = new WebSocket('ws://127.0.0.1:8888');
conn.onopen = function(e) {
console.log("Connection established!");
};
conn.onmessage = function(e) {
console.log(e.data);
};
</script>
我已经尝试使用另一个浏览器,更改端口并不起作用