Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which websocket library to use with Node.js? [closed]

Currently there is a plethora of websocket libraries for node.js, the most popular seem to be:

  • https://github.com/Worlize/WebSocket-Node
  • https://github.com/einaros/ws
  • https://github.com/LearnBoost/engine.io
  • https://github.com/learnboost/socket.io
  • https://github.com/sockjs

However I can't find any solid concrete comparisons between any of them... Apparently Socket.io was awesome, but has become quite dated and has failing builds. Both ws and websocket-node claim they are the fastest. And engine.io seems new, but a lot heavier than the lighter aletarntives.

It would be amazing if we or someone could put together an answer that serves as a guide on which socket library to use and when, as well as a comparison between them.

like image 715
balupton Avatar asked May 06 '13 05:05

balupton


People also ask

Is Node JS good for WebSockets?

Node. js can maintain many hundreds of WebSockets connections simultaneously. WebSockets on the server can become complicated as the connection upgrade from HTTP to WebSockets requires handling. This is why developers commonly use a library to manage this for them.

Can WebSockets close servers?

Find out how to close a websocket connection in JavaScript. To close a WebSocket connection, you can simply use the WebSocket. close() method, for example, like so: const ws = new WebSocket('ws://localhost:8080'); // ...

How do I close a node JS WebSocket?

Jus use ws. close() in this way.


1 Answers

Getting the ball rolling with this community wiki answer. Feel free to edit me with your improvements.

  • ws WebSocket server and client for node.js. One of the fastest libraries if not the fastest one.

  • websocket-node WebSocket server and client for node.js

  • websocket-driver-node WebSocket server and client protocol parser node.js - used in faye-websocket-node

  • faye-websocket-node WebSocket server and client for node.js - used in faye and sockjs

  • socket.io WebSocket server and client for node.js + client for browsers + (v0 has newest to oldest fallbacks, v1 of Socket.io uses engine.io) + channels - used in stack.io. Client library tries to reconnect upon disconnection.

  • sockjs WebSocket server and client for node.js and others + client for browsers + newest to oldest fallbacks

  • faye WebSocket server and client for node.js and others + client for browsers + fallbacks + support for other server-side languages

  • deepstream.io clusterable realtime server that handles WebSockets & TCP connections and provides data-sync, pub/sub and request/response

  • socketcluster WebSocket server cluster which makes use of all CPU cores on your machine. For example, if you were to use an xlarge Amazon EC2 instance with 32 cores, you would be able to handle almost 32 times the traffic on a single instance.

  • primus Provides a common API for most of the libraries above for easy switching + stability improvements for all of them.

When to use:

  • use the basic WebSocket servers when you want to use the native WebSocket implementations on the clientside, beware of the browser incompatibilities

  • use the fallback libraries when you care about browser fallbacks

  • use the full featured libraries when you care about channels

  • use primus when you have no idea about what to use, are not in the mood for rewriting your application when you need to switch frameworks because of changing project requirements or need additional connection stability.

Where to test:

Firecamp is a GUI testing environment for SocketIO, WS and all major real-time technology. Debug the real-time events while you're developing it.

like image 173
22 revs, 11 users 63% Avatar answered Oct 10 '22 09:10

22 revs, 11 users 63%