Is there some way to PUSH data from web server to

2019-01-01 03:24发布

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?

18条回答
永恒的永恒
2楼-- · 2019-01-01 03:38

There are other methods. Not sure if they are "better" in your situation. You could have a Java applet that connects to the server on page load and waits for stuff to be sent by the server. It would be a quite a bit slower on start-up, but would allow the browser to receive data from the server on an infrequent basis, without polling.

查看更多
爱死公子算了
3楼-- · 2019-01-01 03:39

I would strongly suggest to invest some time on Comet, but I dont know an actual implementation or library you could use.

For an sort of "callcenter control panel" of a web app that involved updating agent and call-queue status for a live Callcenter we developed an in-house solution that works, but is far away from a library you could use.

What we did was to implement a small service on the server that talks to the phone-system, waits for new events and maintains a photograph of the situation. This service provides a small webserver.

Our web-clients connects over HTTP to this webserver and ask for the last photo (coded in XML), displays it and then goes again, asking for the new photo. The webserver at this point can:

  • Return the new photo, if there is one
  • Block the client for some seconds (30 in our setup) waiting for some event to ocurr and change the photograph. If no event was generated at that point, it returns the same photo, only to allow the connection to stay alive and not timeout the client.

This way, when clients polls, it get a response in 0 to 30 seconds max. If a new event was already generated it gets it immediately), otherwise it blocks until new event is generated.

It's basically polling, but it somewhat smart polling to not overheat the webserver. If Comet is not your answer, I'm sure this could be implemented using the same idea but using more extensively AJAX or coding in JSON for better results. This was designed pre-AJAX era, so there are lots of room for improvement.

If someone can provide a actual lightweight implementation of this, great!

查看更多
浮光初槿花落
4楼-- · 2019-01-01 03:40

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.

查看更多
谁念西风独自凉
5楼-- · 2019-01-01 03:40

Might want to look at ReverseHTTP also.

查看更多
皆成旧梦
6楼-- · 2019-01-01 03:43

Yet another, standard, way is SSE (Server-Sent Events, also known as EventSource, after the JavaScript object).

查看更多
临风纵饮
7楼-- · 2019-01-01 03:43

You could try out our Comet Component - though it's extremely experimental...!

查看更多
登录 后发表回答