DEV Community

Discussion on: WebSocket Simplified

Collapse
 
devworkssimone profile image
DevWorksSimone

Nice article, came here before reading the following. Still I cant see whats the difference from long polling ti websocket and is not you it must br me who cant gran it. So normal polling is different from long as it keep open connections and ask then conn get closed. Long polling open once for an established amount of time (server estabilish time) so you dont make multiple connection. Whats is changing in ws? You keep the connection open like in long polling ....

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.