Implementation of message push

News push:

  There are many ways to use message push. The principle is roughly as follows: the mobile terminal maintains a long connection with the message server. Once the server has a message, it is pushed to the client, and the client receives the message and handles it accordingly.

Several implementations of message push:

  The B/S architecture system mostly uses the HTTP protocol, so let's take a look at the HTTP protocol first:

Features of the HTTP protocol:
  List content
  statelessness;
  Send request messages and response messages over the Internet;
  Use the port to receive and send messages, the default is port 80; but the bottom layer is still done using Socket.

  The HTTP protocol determines the connection method between the server and the client, and cannot directly implement message push. 
  So there are some disguised solutions:  two-way communication and message push .

1. Polling:

The client sends Ajax requests to the server regularly, and the server returns the response information immediately after receiving the request, and closes the connection.

Advantages: It is easier to write back-end programs 
Disadvantages: Most of the requests are useless, wasting bandwidth and server resources 
Example: Suitable for small applications

2. Long polling:

The client sends an Ajax request to the server, the server holds the connection after receiving the request, returns the response information and closes the connection until there is a new message; the client sends a new request to the server after processing the response information.

Advantages: No frequent requests in the absence of messages, less resource consumption 
Disadvantages: The server Hold connection will consume resources, the order of returned data cannot be guaranteed, and it is difficult to manage and maintain 
Examples: WebQQ, Hi web version, FaceBook IM, etc.

3. Long connection:

Embed a hidden jframe in the page, set the src attribute of the hidden iframe to a request for a long connection or use an XRH request, the server can continuously input data to the client.

Advantages: messages arrive instantly, no useless requests are sent; it is relatively convenient to manage 
Disadvantages: the server maintains a long connection will increase the cost 
Example: Gmail chat

4.Flash Socket:

A Flash program using the Socket class is embedded in the page. JavaScript communicates with the Socket interface on the server side by calling the Socket interface provided by the Flash program. After receiving the information sent by the server, JavaScript controls the display of the page.

Advantages: Real-time communication, not pseudo-instant 
Disadvantages: Flash plug-in must be installed on the client side; non-HTTP protocol, cannot automatically pass through firewalls 
Example: Network interactive game

5.WebSocket:

WebSocket is a network technology provided by HTML5 for full-duplex communication between the browser and the server; relying on this technology, a long connection between the client and the server, and two-way real-time communication can be realized.


Advantages : event-driven; asynchronous; client Socket using WS or WSS protocol; able to realize the push function in the true sense 

 

refer to:

  https://blog.csdn.net/wangchengiii/article/details/77895280

  https://88250.b3log.org/web-message-push

  Summary of several message push schemes for Android: https://www.cnblogs.com/Joanna-Yan/p/6241354.html

Guess you like

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