I am building a web app (or a mobile app). Can I eliminate HTTP altogether and use WebSockets?

Not completely. To  perform a websocket handshake , one needs HTTP. Once the handshake is successful, you can switch to websockets entirely. If your app runs in a browser, you may also need to serve a HTML/JavaScript file(s) for the landing page, which will require HTTP.

What are the advantages and disadvantages of this solution?

Advantages

  • Full Duplex, stateful communication (unlike HTTP).
  • Real server push (you can easily notify clients) .
  • Add a layer on top of WebSockets (e.g. json rpc), and you can outperform HTTP.

Disadvantages

  • Bare bones TCP, so your  app may require another protocol on top of that. Which could affect performance and reliability. Especially if you want to mix textual content (e.g. json) with binary content (e.g. images). You may end up reinventing the HTTP protocol over websockets.
  • Not as many tools as for HTTP

What about Socket.io?

  1. Socket.io was designed to handle some shortcomings of websockets.
  2. Addresses Connection dropping issues with WebSockets.
  3. Old Browser Fallback capability.

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.