websocket服务器握手协议

时间:2021-12-01 10:06:23

测试网页代码如下

<!DOCTYPE html>
<html>
<head>
<title>测试 websocket 世界最简单案例</title>
</head>
<body>
<script>
var ws = new WebSocket("ws://127.0.0.1:8001/index.html"); ws.onopen = function(){
alert("open");
ws.send("WebSocket");
};
ws.onmessage = function(ev){
alert(ev.data);
};
ws.onclose = function(ev){
alert("close");
};
ws.onerror = function(ev){
console.log(ev);
alert("error");
};
</script>
</body>
</html>

websocket服务器握手协议