Explain WebSockets Like I'm Five

tl;dr

WebSockets are like a phone conversation. Traditional HTTP is like a radio.

What is a WebSocket?

A WebSocket connection is like a telephone. Both the client and the server can freely send messages back and forth over a single connection TCP.


A traditional http POST, GET, etc. is like a walkie-talkie. The server will only respond to a client's message, they cannot freely send messages back and forth.

In this example we're using the proper way to talk on a walkie-talkie, i.e. after the other person has finished talking with "over".

An HTTP request also has to create a new connection each time. While this isn't a big deal for a single request, it can be a problem if you're making a lot of them.

A WebSocket server can also broadcast messages to all connected clients. Not limited to the 1-1 relationship of a traditional http request. This is where the metaphore falls apart. In this sense, a WebSocket is more like a loud speaker.