message system (transfer)

1. How does http receive messages in real time like tcp?

    How long polling actually works

    1) Message connection: An http connection is established between webim and webserver, which is specially used as a message channel. This connection is called an http message connection.

    2) Four characteristics of message connection

          a. When no message arrives, the http message connection will be held and not returned. Since http is a short connection, the http message connection will be held for at most 90 seconds before being disconnected (this is the browser or webserver's behavior)

          b. In the case of 1), if the http message connection is disconnected, immediately initiate another http message connection [see steps 1 and 2 in the following figure]

          c. With the cooperation of 1) and 2), there will always be a message connection between the browser and the webserver (4) in the extreme case. Every time a message is received, this message connection will be able to send the message in time. Bring back the browser page, and after returning, it will initiate another http message connection immediately

          d. If the last http message connection is returning when the message arrives, and no http message connection is available (theoretically, the return of the http message connection is instantaneous, and the probability of no connection being available is extremely small), then temporarily store the message in the message pool , after the next message connection arrives (previous

              After the message connection is returned, according to 2) and 3), a new message connection will be returned immediately (no waiting time), the message will be brought back, and a new message connection will be generated immediately.

         in conclusion:

         Webim can guarantee the absolute real-time of messages through http long polling. This real-time guarantee is not guaranteed by increasing the polling frequency, but by holding down the http message connection . In the absence of real-time messages most of the time, this http message connection

         The request pressure is once every 90 seconds, which can greatly save web server resources.

         Reprinted from: https://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&mid=2651959605&idx=1&sn=21f25087bef3c3a966ef03b824365621&scene=21#wechat_redirect

 

2. 

 

Guess you like

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