views:

1110

answers:

6

Is there a general way to implement part of an application with JavaScript and supplying a persistent connection to a server? I need the server to be able to push data to the client, regardless of the client being behind a firewall. Thanks in advance

+2  A: 

You should look into Comet:

http://ajaxian.com/archives/comet-a-new-approach-to-ajax-applications

BobbyShaftoe
+1  A: 

With HTTP, the connection has to start from the client. But there are techniques available for having the server hold the connection open and flush data as needed.

These are generally considered to be Comet or HTTP Streaming architectures.

Jonathan Lonowski
+5  A: 

See Comet - it's like ajax, but it holds a connection open so the server can push information to the client.

Note that most browsers will only hold 2 connections to a particular domain (by default), so you'll want to split your domains (e.g. www.yourdomain.com and comet.yourdomain.com) so that you don't drastically slow down the loading of your pages. Or you could just make sure you don't open the comet connection until everything else is loaded. It's just something to be careful of.

Stephen
A: 

Thanks a lot, this looks just like the kind of thing I need!

Ulf
You should up vote the helpful comments, and accept one
Stephen
i'm not allowed to upvote yet, but i will
Ulf
+1  A: 

You can use Comet programming techniques for this. Basically the page makes a call to the server that doesn't return until the server has something to send (at which point the client immediately makes the same call). This way the server can push content to the client pretty much whenever it wants.

Support varies depending on platform and is more an issue with the server than the client.

cletus