websocket服务器握手协议

测试网页代码如下

<!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>

 

 

 

posted @ 2018-03-06 20:05  jadeshu  阅读(250)  评论(0)    收藏  举报