Is there some way to PUSH data from web server to browser?

74,806

Solution 1

Yes, what you're looking for is COMET http://en.wikipedia.org/wiki/Comet_(programming). Other good Google terms to search for are AJAX-push and reverse-ajax.

Solution 2

Yes, it's called Reverse Ajax or Comet. Comet is basically an umbrella term for different ways of opening long-lived HTTP requests in order to push data in real-time to a web browser. I'd recommend StreamHub Push Server, they have some cool demos and it's much easier to get started with than any of the other servers. Check out the Getting Started with Comet and StreamHub Tutorial for a quick intro. You can use the Community Edition which is available to download for free but is limited to 20 concurrent users. The commercial version is well worth it for the support alone plus you get SSL and Desktop .NET & Java client adapters. Help is available via the Google Group, there's a good bunch of tutorials on the net and there's a GWT Comet adapter too.

Solution 3

Nowadays you should use WebSockets. This is 2011 standard that allows to initiate connections with HTTP and then upgrade them to two-directional client-server message-based communication.

You can easily initiate the connection from javascript:

var ws = new WebSocket("ws://your.domain.com/somePathIfYouNeed?args=any");
ws.onmessage = function (evt) 
{
  var message = evt.data;
  //decode message (with JSON or something) and do the needed
};

The sever-side handling depend on your tenchnology stack.

Solution 4

Look into Comet (a spoof on the fact that Ajax is a cleaning agent and so is Comet) which is basically "reverse Ajax." Be aware that this requires a long-lived server connection for each user to receive notifications so be aware of the performance implications when writing your app.

http://en.wikipedia.org/wiki/Comet_(programming)

Solution 5

Comet is definitely what you want. Depending on your language/framework requirements, there are different server libraries available. For example, WebSync is an IIS-integrated comet server for ASP.NET/C#/IIS developers, and there are a bunch of other standalone servers as well if you need tighter integration with other languages.

Share:
74,806
Niyaz
Author by

Niyaz

I hang out here.

Updated on August 07, 2020

Comments

  • Niyaz
    Niyaz almost 4 years

    Of course I am aware of Ajax, but the problem with Ajax is that the browser should poll the server frequently to find whether there is new data. This increases server load.

    Is there any better method (even using Ajax) other than polling the server frequently?

  • Corehpf
    Corehpf almost 15 years
    Definitely the way to go, once you get into implementing it yourself you realize how much there is to do - reconnection, long-polling, streaming iframes, cross-browser support, HTTPS...
  • Kevin Monk
    Kevin Monk almost 15 years
    An explanation of what Comet is would help this answer
  • Nosrama
    Nosrama almost 15 years
    @Satir: added a quick explanation. Other answers have links to the Wikipedia article.
  • Ciro Santilli OurBigBook.com
    Ciro Santilli OurBigBook.com over 8 years
  • Ciro Santilli OurBigBook.com
    Ciro Santilli OurBigBook.com over 8 years
  • Nick Steele
    Nick Steele almost 8 years
    I totally agree... Using HTTP for bi-directional communication is like thinking in REST calls to make Mario jump on turtle shells... it's insanity. You don't NEED to make requests and wait for responses for simple button pushes people.... You just don't. HTTP is a document protocol. Hyper TEXT Transfer Protocol. Ajax Push is an insanely complex way to circumvent HTTP to do what WebSocket does by design. Stop being goofy and use the right tool for the job.
  • imbatman
    imbatman over 5 years
    you really like ellipses, and sometimes a new form of four dots which I shall call "ellipsos"!