Sec-WebSocket-Extensions: deflate-frame means that the browser supports data compression. There may be additional headers Sec-WebSocket-Extensions and Sec-WebSocket-Protocol that describe extensions and subprotocols. Upon seeing it, the browser understands that the server really does support the WebSocket protocol.Īfterwards, the data is transferred using the WebSocket protocol, we’ll see its structure (“frames”) soon. Here Sec-WebSocket-Accept is Sec-WebSocket-Key, recoded using a special algorithm. Sec-WebSocket-Accept: hsBlbuDTkk24srzEOTBUlZAlC2g= When new WebSocket(url) is created, it starts connecting immediately.ĭuring the connection, the browser (using headers) asks the server: “Do you support Websocket?” And if the server replies “yes”, then the talk continues in WebSocket protocol, which is not HTTP at all. That’s actually it, we can talk WebSocket already. So you’ll see events open → message → close. It responds with “Hello from server, John”, then waits 5 seconds and closes the connection. de is usually 1006 in this caseįor demo purposes, there’s a small server server.js written in Node.js, for the example above, running. Let socket = new WebSocket("wss:///article/websocket/demo/hello") Īlert(` Data received from server: $`)
0 Comments
Leave a Reply. |