Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way for the server to send messages to a web client?

Links to articles would also be appreciated--I don't know the terminology to search for.

I'm looking to learn how a web application can allow for server-to-client communications. I know the web was not designed for this and that it has been something of a hurdle, and am just wondering what the state of this is, and what the best practices are.

An alternative is constant or occasional polling via ajax, but is it possible for web servers to maintain stateful connections to a web client?

Edit: Another way to ask this question is how does StackOverflow tell a page that new posts are available for it to display that little bar at the top?

like image 250
devios1 Avatar asked Oct 14 '25 16:10

devios1


2 Answers

StackOverflow polls the server to check if there is more data.

What you're looking for is Comet.

like image 174
Sophie Alpert Avatar answered Oct 17 '25 04:10

Sophie Alpert


To get true two way communications from a browser you need to use a plugin technology like Silverlight, Flash, et al. Those plugins can create TCP connections that can establish a two way persistent connection with a server socket. Note that you can't really establish the TCP connection with the HTTP server so you'd have to create an additional server agent to do the communicating back to the browser.

Basically it's a completely differnet deployment model to what AJAX sites like Stackoverflow, Gmail etc. use. They all rely on the browser polling the server at set intervals.

like image 20
sipsorcery Avatar answered Oct 17 '25 05:10

sipsorcery