im用棘轮开发了一个websocket,当我尝试连接它时,几分钟后,它仅显示“与'ws://127.0.0.1:8888 /的WebSocket连接失败:WebSocket打开握手超时”在控制台中,但在外壳程序中显示:
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>
我尝试使用其他浏览器,更改了端口,但仍无法正常工作