user7965410 user7965410 - 4 months ago 26
Javascript Question

Connection stream

Is there another way to create a connection stream between a loaded page (client) and the server without using repeated AJAX calls, like every half second? I think of something that will make the client listening until the server gives a response (which can take a few seconds to arrive).

Thank you for your answers.

ju_ ju_
Answer Source

I would like to recommd you Phil Leggetter's Guide to Real-time technologies - because that is what you are looking for.

You will need one of the html5 introduced connection aspects: WebSockets, Server-Sent Events or even WebRTC DataChannel could be possible if you have a peer-to-peer use case.

In reference to the above link, its always about your server setup and your use case - that in mind some commonly used technologies would be: Pusher, Firebase,, Ratchet, etc.


Server-sent-events do have more server-side compatibilitly, technically it is more like optimized HTTP streaming, you can read more details in the spec and on caniuse. If you need a constant bidirectional connection and better client side support you better go with WebSockets. But you will need to set up a compatible server or use an external service like Pusher or Firebase.