Why you should never use Socket.IO
github.com
github.com
The title is doubly worse because it doesn't actually promote the library. You could quote the repo instead - "mWebSockets - a lightweight, efficient & scalable WebSocket server"
The reason I've selected socket.io for projects in the past is because of the awesome documentation and slick marketing, not because of snarky attacks on other libraries.
Any ideas how we can achieve something similar using µWS? I guess using it as the engine in Socket.IO would do it, but let’s assume we want to get rid of Socket.IO entirely.
[1] http://socket.io/docs/rooms-and-namespaces/#sending-messages...
I use it in production (BTorrent tracker) with 700-1300 peers active 24/7. 50MB or less RAM usage.
socket.emit('msg', 'hello', (err) => ...)
At which point the nice part of using socket.io is that there are a variety of clients (and server impls) so every one of your users doesn't need to implement things like message_id callbacks.Sadly I cannot (yet) present the pub/sub benchmarks of deepstream.io vs Socket.IO but I promise you: it will be hilarious.
Other projects that have been shown to outperform Socket.IO include SocketCluster, which use µWS as the default engine.
const e = new EventEmitter();
socket.on('message', msg => e.emit(msg.data.type, msg.data));
Also websockets have far better server and client support. There's websocket implementations in basically every major language as well as most popular load balancers on the market today.When socket.io first came out it was very needed. But now websockets are supported in all major browsers, including mobile: http://caniuse.com/#search=websockets
The client stores its own message_id -> callback mapping, it has to send some sort of reply id for the server or agree on some other mechanism, and it's not something you want to have to build on every project, just like exponential reconnect backaway.
And I'm not sure why you'd want to use the native WebSocket API by itself except on toy apps.
You never have to "build it again for every project" if you put your code in npm. But I guarantee you there are dozens of libraries like this in npm already. (Just like there are dozens of libraries to do exponential reconnect backoff.)
The right approach is to build / use light layers on top of websockets to solve these problems. Socket.io is the wrong solution. Its the wrong solution for every problem.
I would recommend WebSocket++ or libwebsockets (if you are not going with µWebSockets).
But today anyone building new applications should use websockets. Browser support is excellant, speed is great, firewall penetration is fantastic if you run your site on HTTPS. You gain cross-server language compatibilty, you avoid socket.io's awful design decisions around reconnection, error handling and code quality.