WebSockets–versus HTTP

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.

Cloud Advisory Services | Security Advisory Services | Data Science Advisory and Research

Specializing in high volume web and cloud application architecture, Anuj Varma’s customer base includes Fortune 100 companies (dell.com, British Petroleum, Schlumberger).

All content on this site is original and owned by AdverSite Web Holdings, Inc. – the parent company of anujvarma.com. No part of it may be reproduced without EXPLICIT consent from the owner of the content.

Anuj Varma – who has written posts on Anuj Varma, Technology Architect.


Leave a Reply

Your email address will not be published. Required fields are marked *