Shark Deng

Interactive Designer @Shanju Design in Shanghai

touched caffe / mxnet / python / wordpress / bootstrap / Arduino / Raspberry Pi / webgl / three.js / PIXI / 3dMax

Email

Github

Websocket – html客户端

2019-11-18 21:22:19

<html>	
	<head>
		<meta charset="utf-8"/>
		<title>stWebsocketServer</title>
	</head>
	
	<body>
		<script>
			function Test(){
			//1//if (window.WebSocket){}
				if ("WebSocket" in window){
					alert("support");
					var ws = new WebSocket("ws://echo.websocket.org");
					ws.onopen = function(e){
						ws.send("send data");
						alert("sending ");
					}
					ws.onmessage = function(e){
						var msg = e.data;
						alert("msg received:  " + msg);
					}
					ws.onclose = function(e){
						alert("close")
					}
					ws.onerror = function(e){
						alert("error");
					}
				} else {
					alert("not support");
				}
			}
			Test();
			//window.addEventListener('load','Test',false);
		</script>
	
	</body>


</html>

 



——By SharkDeng
如果你喜欢我的文章,欢迎红包赞赏

Leave a Reply

Your email address will not be published. Required fields are marked *