Question

What is the best technology to use if I want to make instant user notification, like StackOverflow has?

I consider SSE and WebSockets. What are pros and cons of each solution?

Should I use socket.io or better to use WebSockets directly?

Was it helpful?

Solution

The main difference is that with SSE you can only receive messages from the server. You cannot send messages to the server. Everything doable with SSE is doable with WebSockets. But not vice versa - WebSocket is capable of sending data to the server. So from that point of view WebSockets win. I can't really see any advantage of SSE (perhaps performance?), but then again I don't have much experience with it.

Note that StackOverflow uses WebSockets. They might have some fallback for older browser, I don't know about that.

As for the third question: perhaps you should ask what language you want to use in the first place? I've been working with WebSockets and Python and it worked really well. You could work with WebSockets directly. The advantage of using socket.io is mostly the fallback (assuming it matters - it does not IMHO): if WebSockets are not available it can automatically switch to other ways of communication (like Flash or long polling). The disadvantage is that it is Node.js (in the sense that you have to restrict yourself to one language) plus there are some performance issues, i.e. socket.io does not scale well beyond one machine.

OTHER TIPS

You might consider using a library like SocketIO that abstracts out the transport layer, so you don't have to worry about the mechanics of how the real-time connection is maintained. This will save you a TON of headaches.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top