Persistent connection with client

后端 未结 5 1427
轻奢々
轻奢々 2021-02-08 06:10

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 cl

相关标签:
5条回答
  • 2021-02-08 06:28

    You should look into Comet:

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

    0 讨论(0)
  • 2021-02-08 06:38

    Here are a few questions in a similar vein. And of course all the questions tagged comet

    • Implementing a self resetting XMLHttpRequest object
    • Server-side Push in Rails
    • Is there an alternative of ajax that does not require polling without server side modifications?
    • Long-lived connections (asynchronous server push) with Apache/PHP/Javascript?
    0 讨论(0)
  • 2021-02-08 06:40

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

    Note that compliant browsers will only hold 2 connections (note: most modern browsers no longer comply) to a particular domain (by default), so you might 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.

    0 讨论(0)
  • 2021-02-08 06:45

    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.

    0 讨论(0)
  • 2021-02-08 06:46

    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.

    0 讨论(0)
提交回复
热议问题