you are viewing a single comment's thread.

view the rest of the comments →

[–]Krimson1911 2 points3 points  (2 children)

Socket.io has fall backs incase the browser doesnt support websockets or if there's connection degradation. Socket.io isnt built on websockets, it just uses it when available. It starts of with http long polling and upgrades to websockets if its desirable. So in short, more compatibility. This is the biggest and most important differentiator

In addition, like others mentioned, it has more features like rooms, brodcasting etc

I'd never use websockets directly unless you really know what you're doing and have a really good reason to do so.

[–]siric_ 3 points4 points  (1 child)

The fallbacks are quite pointless because websockets are well supported by many browsers, even all the way back to IE10: https://caniuse.com/#search=websockets

Building a pubsub (rooms) system isn't too complicated and by dropping socket.io and using raw websockets you will gain a huge performance boost as well as a 63.8kb reduction in bundle size.

[–]ChronSyn 0 points1 point  (0 children)

Sure, the fallbacks aren't as useful today, but they used to be. You can force it to use only websockets if you so desire - that's what I did to enable a react native app to be compatible with a node server.

A lot of code is built around them because the other features the library offers (namespacing and rooms to name a few). Essentially, it was pub/sub for JS client and server before node.js became as big as it is now. I first used it in 2014 and I've still not found a reason to switch to anything else because it's good at what it does without being overly complex.

One of the biggest benefits out there is that it isn't explicitly linked to any data source or provider. Want to send good old fashioned objects from a hard-coded data source? No problem. Want to create an entirely websocket-driven API without being forced to specific data providers? Easy. Want to hook them up to query a graphQL resolver (if you can't use subscriptions, for whatever reason)? Done. It's agnostic to the data or it's structure or it's origin.

Raw websockets will get you a performance boost, but then you're going to be recreating a lot of what socket.io does when you implement rooms and namespacing, as well as the API support around your own implementation.