views:

108

answers:

3

Obviously, you can't push data to a web application, as HTTP works in a request-response cycle.

But what hacks/methods do you know of that can imitate pushing data to a client?

+6  A: 

You could use what is known as Comet: http://en.wikipedia.org/wiki/Comet_(programming), http://stackoverflow.com/search?q=comet

Basically, javascript in the browser makes a request to the server right away (using XmlHttpRequest). The server does not respond until it has some data to serve.

From the article:

The browser makes an asynchronous request of the server, which may wait for data to be available before responding. The response can contain encoded data (typically XML or JSON) or javascript to be executed by the client. At the end of the processing of the response, the browser creates and sends another XHR, to await the next event. Thus the browser always keeps a request outstanding with the server, to be answered as each event occurs.

codeape
+1  A: 

In some instances polling i.e. sending a request at a regular (short) interval might suffice. But the answer given above - Comets - is the closest thing to the real deal as far as sending data without a client request is concerned.

Ankur
+1  A: 

You're limited to polling in HTTP. One of the early Netscape browsers did implement HTTP push I seem to recall, back at the start of the century but it didn't get anywhere.

You can't use raw sockets with Flash, Javascript/Xml, Silverlight. With Java, and Active-X you can, but you'll need a certificate. The Quake Live shows this off, all the networking is obviously still UDP based but inside a browser plugin for IE or Firefox.

So polling, polling, polling.

Chris S