一、官网
官网地址:http://www.websocket.org/
二、websocket初识demo
<input id="sendTxt" type="text"/> <button id="sendBtn">发送</button> <div id="recv"></div> <script type="text/javascript"> var ws = new WebSocket("ws://echo.websocket.org/"); ws.onopen = function () { console.log("websocket open"); document.getElementById("recv").innerHTML = "connected"; } ws.onclose = function () { console.log("websocket close"); document.getElementById("recv").innerHTML = "closed"; } ws.onmessage = function (e) { console.log(e.data); document.getElementById("recv").innerHTML = e.data; } document.getElementById("sendBtn").onclick = function () { var txt = document.getElementById("sendTxt").value; ws.send(txt); } </script>