DEV Community

Discussion on: WebSocket Simplified

Collapse
 
iamshadmirza profile image
Shad Mirza

Glad you asked. HTTP is not meant for keeping the connection open. It is the usage that matters. HTTP is designed to serve multiple requests a quickly as possible, hence open connection -> server -> close connection whereas WebSockets are designed for longer connection. You can take another look at the header, we are upgrading to TCP protocol which means we are saving a lot of resources here. How?

  1. HTTP is not on hold (it is just being used for handshaking i.e. establishing a connection and then the connection is closed) which means we can use it for serving other short term quick requests.
  2. Server-side is not sending no/zero payload to specify that data is not available. It is also free to serve other requests.