11

I am learning Node.js and am currently studying WebSockets. As I understand it, Socket.io was intended to address inconsistent support that the various browsers had with WebSockets...If you check out caniuse WebSockets, it appears that WebSockets currently has practically full support. Can anyone explain why I should use Socket.io versus WebSockets in this case?

Danny Bullis
  • 3,043
  • 2
  • 29
  • 35
  • it is not what i would call full supoort imho , unless you dont care about legacy desktops and mobile browsers that account for at least half of the deployed browsers in the western wolrd,that will still be in use for the next 5 years, and will never support websocket. – mpm Mar 03 '13 at 01:44
  • Good point. I noticed that Socket.io figures out which connection method works best and does that for you, based on which browser you're using. Actually, that's probably the answer right there. I'm sure if you were to just use WebSockets, you'd have to figure out all the code for that yourself. – Danny Bullis Mar 03 '13 at 02:06

1 Answers1

12
  1. It handles graceful degradation for you to numerous technical alternatives to get bi-directional near-time communication flowing (web sockets, ajax long polling, flash, etc)
  2. As of March 2013 that site lists web sockets at 61% support. This is not "practically full".
  3. As of September 2021 that site lists web sockets at 98% support. All modern browser's support Websockets.
  4. It handles browser inconsistencies and varying support levels for you
  5. (these first 2 things are basically the same value created by jQuery, to put it in perspective)
  6. It includes additional features beyond bare bones web sockets such as room support for basic publish/subscribe infrastructure and things like automatic reconnect
  7. AFAIK it is more popular and easier to get help with than vanilla web sockets, at least at the moment.

However, just like there is VanillaJS for the jQuery haters, if you prefer using the official standard web socket APIs directly, by all means, knock yourself out.

mh-anwar
  • 131
  • 3
  • 10
Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
  • 1
    Gotcha. Yeah, I just realized that I totally read the caniuse chart wrong - I didn't consider the fact that not everyone is using the most up-to-date browser :P. Silly mistake. Thanks for your input though! The point you made about jQuery (which I use) makes total sense. Thanks man. – Danny Bullis Mar 05 '13 at 08:07
  • Good comment. While a lot of stuff has changed over the course of 2 years since you've answered this question, I believe #4 is the better answer of them all. If you want to go vanilla sockets, skip Socket IO. If you are looking for a more graceful integration, go check it out. Naturally, if someone disagrees, feel free to correct me! :) – ReSpawN Jul 19 '15 at 15:27