4 ms·
i actually went through this debate a few days ago when deciding what to use for realtine updates on our new platform. I had previously used socket.io but decid
by coltonv 11y ago
i actually went through this debate a few days ago when deciding what to use for realtine updates on our new platform. I had previously used socket.io but decided I'd try just using straight websockets and not bothering backporting realtine updates to IE9. Really great decision IMO. The basic Websocket API is actually really easy to use. i got everything up and running in less than a day, the server is less than 100 lines, and the client side code is about 50 lines and completely resuable and DRY wherever i need realtime updates. Compare this to the 100kb (minified) and all sorts of boilerplate you have to write for socket.io, so in my opinion you're better off with straight WebSockets these days.
- XCSme 11y agoSee this: https://gist.github.com/zeusdeux/5491cff541fb4ac4c142 https://gist.github.com/zeusdeux/5491cff541fb4ac4c142 I myself prefer the extra 100kb if I receive in exchange a more robust client/server architecture with browser fallback.
- coltonv 11y agoThat link mentions that it's both a server and a client, which made me realize i didn't mention what i used server side. I used https://github.com/sitegui/nodejs-websocket/blob/master/README.md https://github.com/sitegui/nodejs-websocket/blob/master/READ... which is extremely easy to set up and use. i don't doubt the value of socket.io but I for my purposes it was not optimal.
- dcwca 11y ago> and the client side code is about 50 lines and completely resuable and DRY Were you able to implement auto-reconnect with backoff? That's one of the most important features that something like Socket.io gives you.
- coltonv 11y agoRight now just a 3 time retry with hard coded delay between each one.
- jkarneges 11y agoIf you don't need fallback to HTTP, there are some alternative libraries that handle auto reconnect for pure WebSockets: https://github.com/fanout/websockhop https://github.com/fanout/websockhop https://github.com/joewalnes/reconnecting-websocket https://github.com/joewalnes/reconnecting-websocket
- dtf 11y agoAlso, if your traffic is basically one-way like in this example, don't forget Server-Sent Events, which are auto-reconnecting and well supported.
- mailanik 11y agoi recently made a messaging app something like appear.in using websockets in less than a day. Just added nodejs cluster support to it. Kind of easy to learn and easy set up made me love websockets.