Learning Question

What actually changes when a connection becomes WebSocket?

WebSocket begins with an HTTP Upgrade. If the server accepts the upgrade, the same underlying connection is no longer used for ordinary HTTP request-response messages. It is used for WebSocket frames, which allow both sides to send application messages over the persistent connection.

The Upgrade Boundary

The connection starts in HTTP:

client -> HTTP request asking to upgrade
server -> HTTP response accepting upgrade

After that point, the application-layer protocol changes:

same underlying connection
-> WebSocket frames instead of ordinary HTTP request-response messages

WebSocket does not change TCP. It changes how the application interprets bytes flowing over the connection.

Why Keep-Alive Is Not WebSocket

HTTP keep-alive reuses a connection for multiple HTTP requests and responses.

WebSocket changes the communication pattern so either side can send messages without creating a new HTTP request each time.

HTTP keep-alive:
request -> response
request -> response
 
WebSocket:
message <->
message <->
message <->

The difference is protocol semantics, not merely whether the TCP connection remains open.

What WebSocket Is Good For

WebSocket fits communication where both sides may need to send application messages over time:

  • chat
  • collaborative editing
  • multiplayer games
  • live dashboards
  • presence and room state
  • interactive control channels

The main value is not “continuous data” by itself. The main value is bidirectional application messages without a new HTTP request for every server-to-client update.

What WebSocket Does Not Solve

WebSocket does not automatically solve:

  • authentication
  • authorization
  • message persistence
  • offline delivery
  • missed-message recovery
  • duplicate handling
  • room membership
  • multi-server routing
  • application-level ordering after reconnects

It provides a live message channel. The application must still define state, reliability, replay, and recovery rules.

Core Mental Model

WebSocket is an application-layer protocol over an underlying connection.

The durable distinction is:

TCP can carry bidirectional bytes.
WebSocket defines bidirectional application messages.
The application defines what those messages mean and how state is recovered.