Push implementation

method:

    Comet, SSE (Server Sent Events), Web Sockets

1.Comet

    Implementation: long polling and streaming;

    Long polling: (a replica of interrupted polling, segment polling: return directly regardless of whether the data is useful or not) The page initiates a request to the server, and the server keeps the link open until it knows that there is data to send. After sending, close the link, and randomly, the page initiates a new request.

    HTTP Streaming: The browser sends a request to the server, the server keeps the connection open, and the server periodically sends data to the browser. In Firefox, safari, Opera, and Chrome, you can use XHR to implement HTTP streaming by listening to the readystatechange event and detecting whether the value of readyState is 3.


2.SSE

    Is an API or pattern introduced around read-only Comet interactions.


3.Web Sockets

    HTML5 began to provide a protocol for full-duplex communication over a single TCP connection. In the WebSocket API, the browser and the server only need to do a handshake, and then a fast channel is formed between the browser and the server. Data can be transferred directly between the two. After you get the Web Socket connection, you can send data to the server through the  send()  method, and receive the data returned by the server through the  onmessage  event.


    


        

    

    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325325209&siteId=291194637