How do they make real time data live on a web page?

后端 未结 3 1413
半阙折子戏
半阙折子戏 2020-12-29 11:11

How do they do this? I would like to have web pages with data fields that change in real time as a person views the web page. Here is an example.

How do they do this

3条回答
  •  天涯浪人
    2020-12-29 12:01

    There are two approaches:

    Polling

    Client requests data on a regular basis. Uses network and server resources even when there is no data. Data is not quite 'live'. Extremely easy to implement, but not scalable.

    Push

    Server sends data to the client, so client can simply wait for it to arrive instead of checking regularly. This can be achieved with a socket connection (since you are talking about web pages, this doesn't really apply unless you are using Flash, since support for sockets in the browser in the browser is currently immature) - or by using the technique known as 'comet'.

    Neither socket connections nor comet are particularly scalable if the server end is implemented naively.

    - To do live data on a large scale (without buying a boat load of hardware) you will need server software that does not use a thread for each client.

提交回复
热议问题