Web Sockets

Web Sockets

Websockets are based on tcp but unlike http which sends requests one way, data can be send both ways between client and server.

In order to establish a websocket between client and server the client sends a http handshake request with an upgrade header indicating that the client wants to establish a websocket connection. If the server is capable of satisfying a websocket connection and the connection is authenticated, the server responds with a successful response specified by the http code 101 Switching protocol.

Websocket transmits the data in frames, specifying the length, type of the data , whether it’s the final frame, a mask and the data.

Websockets are used in chat apps where bi directional messaging is needed, multi-player games and collaboration apps.  

References:

https://sookocheff.com/post/networking/how-do-websockets-work/