Websocket protocol

WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection. Here full duplex means - they allow both callers to speak and be heard at the same time.

REST vs Websocket

  • REST uses HTTP where websocket communicate over TCP. HTTP is a Hypertext Transfer Protocol, whereas TCP full form is Transmission Control Protocol. HTTP is utilized to access websites, while TCP is a session establishment protocol between client and server. HTTP uses port 80 and TCP uses no port.

  • WebSocket is a stateful protocol, whereas REST is based on stateless protocol, i.e. the client does not need to know about the server and the same holds true for the server.

How is Websocket connection established?

How is Websocket connection established?

  1. To establish a WebSocket connection, an HTTP-based handshake is exchanged between the client and the server.

  1. Once successful, the application-layer protocol is “upgraded” from HTTP to WebSockets. This allows data to be sent or received using WebSockets with a much lower latency and less technical overhead than the traditional HTTP request-response cycle.
  2. For either of those to run smoothly, the application has to establish two-way communication so that both the client app and the server can send messages to one another, at the same time.