When implementing real-time database update the front page refresh

https://blog.csdn.net/fengguangle/article/details/78019880

Q:

Is it only set the timer every second request data to the background by Ajax to achieve it?

A:

1,
nodejs of http://socket.io Li Xun support the above mentioned three ways, and also supports Flash Socket, hidden IFrame, JSONP Polling and other means. http://Socket.io provide mechanisms and supporting the front end server, and is compatible with various browsers, js its front end module determines browser capabilities, Comet adaptively select the most appropriate manner.
 
2,
I know that there are three ways: 1, ajax short connection: client once every second send request, the server receives the request will return results immediately, with or without new data. 2, ajax long connection: the client sends a request, there is no new data query server receives the request, if there is no new data is blocking the request until there is new data or times out. Every client receives a request resend the request immediately after the results are returned. comet looks like is this principle. 3, WebSocket: this is not a HTTP protocol, but rather a tcp protocol, and this stuff Socket name suggests is a stream, you can two-way operation. The disadvantage is that some browsers do not support.
Comparative Delay: m msec is assumed that the network delay, the delay ajax short connection between 1000 ms m, two other substantially only m millisecond delay. Contrast resource consumption: should be 1> 2> 3. However, Comparative 1 and 2 depends on the circumstances, if the two requests very long time interval, then it should be 2> 1> 3.
 
3,
with the comet, in fact, is the ajax. Just after the front end sends a request to the server holding the request. The data is returned to the facts. No data has been maintained in this connection. Would you say if the connection is broken, it timed out, and then launch it off.
----------------
Disclaimer: This article is the original article CSDN bloggers "fengguangle", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/fengguangle/article/details/78019880

Guess you like

Origin www.cnblogs.com/jndx-ShawnXie/p/11566604.html