I wanted to write some articles about real-time push technology for Web messages, but I didn't have time to write articles because I was so busy recently. This paper mainly explains the technical principle and implementation of WEB push based on HTTP1.1 protocol. I used to work at the time have done some use of the web message real-time push project, but the implementation is not very perfect, and even sometimes by Ajax rotation way to achieve. On the internet also found a lot of information, really talk about the point of almost no, many articles are mostly lengthy, said some new names, what "HTTP long Connection", "real-time Push", "Comet long connection Push technology" and so on. But the article that really mentions how to implement real-time push is not seen.
One of my open source projects, webchat, is a web-based chat room system that I did before I graduated, and the code has never been put on GITHUB. Because my graduation thesis design is a real-time push application based on the Android platform, after the development of the Android push system let me have a deeper understanding of the push, to the end of the graduation thesis to think of the chat room project to open, recently put on GITHUB, took a name called webchat, at the beginning also want to call WeChat, then feel very vulgar, at that time also can not think of a good name, feel as long as is a decent English words are possessed. webchat git address is [email protected]:leiminglin/webchat.git, server using PHP implementation, front-end use of javascript,jquery. This project is mainly because webchat used the push technology, want to learn the friend can download to see, the project can be run on almost all browsers, I test IE6 no problem.
Speaking of Web push, have to say Flash WebSocket, this should be better than the HTTP implementation, but now HTML5 out, Flash slowly will fade out of the historical stage. In fact, there are a lot of web message push application, before the HTML5, with more than the Flash, such as Baidu Business Bridge Acridine, Sina Weibo and so on. But these well-known applications are not all using flash implementation, previously found that WEBQQ push is implemented using HTTP, but also do not rule out that some modules are not using Flash.
about how to implement real-time message push, can think of the premise must be a long connection, if not a connection is maintained, how to know that the message has arrived. So it takes a lot of real time to pay for it, and the server needs to keep the client's link. Before using HTTP for real-time push, we need to understand the HTTP protocol, HTTP1.1 is to support long connections, but HTTP is stateless, a request, the server responds, the request is over, it will be disconnected shortly thereafter, can not be on the basis of this connection to respond, and then receive , it is the Socket communication. To implement message real-time push on this basis, you must have a connection to make the request and wait for the message, and let it wait until the next request is made immediately after receiving a message response. The rest is the service side of the matter, the server needs a Socket service to listen to the client's long connection request and send message instructions, so that real-time message push can be implemented, this way to achieve the push is much better than the Ajax rotation, in the case of high real-time requirements, such as chatting, In the case of order payment, it is more resource-saving than the rotation way, which also makes the user feel no delay of the message in time.
The principle and implementation of Web message real-time push technology based on HTTP protocol