

“binary data frames” – contain binary data that parties send to each other.“text frames” – contain text data that parties send to each other.WebSocket communication consists of “frames” – data fragments, that can be sent from either side, and can be of several kinds: Here the server responds that it supports the extension “deflate-frame”, and only SOAP of the requested subprotocols. This optional header is set using the second parameter of new WebSocket.

So, this header describes the data formats that we’re going to use. WebSocket subprotocols are registered in the IANA catalogue. Sec-WebSocket-Protocol: soap, wamp means that we’d like to transfer not just any data, but the data in SOAP or WAMP (“The WebSocket Application Messaging Protocol”) protocols. The header Sec-WebSocket-Extensions is sent automatically by the browser, with the list of all extensions it supports. An extension is something related to transferring the data, functionality that extends the WebSocket protocol. 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: $`)
