WebSocket Introduction
WebSocket is a protocol that HTML5 begins to provide full-duplex communication on a single TCP connection.
In the WebSocket API, the browser and server only need to do a handshake, and then a fast channel is formed between the browser and the server. The data can be transmitted to each other directly between the two.
The browser sends a request to the server to establish a WebSocket connection through JavaScript, and after the connection is established, the client and server can exchange data directly via a TCP connection.
When you get a Web Socket connection, you can send data to the server via the Send () method and receive the data returned by the server through the OnMessage event.
Service-side Open source project
Websockets/ws
Nodejs project, test pass.
Tootallnate/java-websocket
Java project, test pass.
Theturtle32/websocket-node
dependent on the Python/vs C + + development environment, the test run passed.
WebSocket API parsing
WebSocket Property
WebSocket Events
WebSocket method
/** * websocket Test * http://www.runoob.com/html/html5-websocket.html*/varws;/** * Connect websocket server*/functionWebsocketconnect () {if("WebSocket"inchwindow) {ws=NewWebSocket ("ws://localhost:9003"); Ws.onopen=function() {Console.log ("WebSocket Server connected ...") }; Ws.onmessage=function(res) {varmsg =Res.data; Console.log (msg); }; Ws.onerror=function() {Console.log ("Connect error ..."); }; Ws.onclose=function() {Console.log ("Disconnect ..."); }; }}/** * Send data*/functionsendmsg () {if(WS) {ws.send ("0xaa,0xbb"); }}/** * Close connection*/functionclosews () {if(WS) {ws.close (); WS=NULL; Console.log ("Closed ..."); }}
Reference:
HTML5 WebSocket
WebSocket Introduction (ii)-websocket API
WebSocket Study (iii)--build a server with Nodejs
HTML WebSocket Notes