Websocket (Protocol)

Definition:

An Internet protocol (specified in 2011 RFC 6455) that enables a server and a client to continuously sending data back and forth to each other by keeping the connection open.

In typical HTTP protocol the client sends one request to server, gets one response, and closes the connection. Thus for continuous communications the client and the server must continuously connect to each other. This generates a lot of latency and slows down the connection.

 

Furthermore, for HTTP if the server wants to send data to client it must know client’s IP address. This is not possible when the client sits behind a firewall (eg: your PC that sits behind the router).

 

Using websocket enables the server to send message to client directly after the client initiates the connection. Since the connection remains open, the server can freely communicate to the client afterwards. This makes real-time two way communication possible.

Analogy:

  • single-trip bus ticket (HTTP) vs full-day pass.