Rookie interview will know HTTP knowledge (five) – New Technology

With the continuous development of the Internet, HTTP has been a bottleneck in many application scenarios, in order to compensate for these shortcomings, some such as Ajax, Comet, WebSocket, JSON and other new technologies, applications and advantages and disadvantages of this article to talk about these new technologies.

1 – HTTP bottleneck

In the establishment of the HTTP Standard Specification, the main idea of the HTTP as the transmission of HTML documents agreement. With the development of the times, the use of Web is more diverse, and the characteristics of HTTP become the bottleneck of performance. However, the use of HTTP based Web browser environment has been around the world, so we can not completely abandon the HTTP, so some of the new protocol based on HTTP as a supplement appeared!

HTTP (version 1) has become the bottleneck of the performance of a connection can only send a request. Requests can only start from the client. The client cannot receive an instruction request / response header other than the response. The more information you have, the greater the delay. Each time the same headers are sent to each other, the data can be arbitrarily selected. Non forced compression

2 – Ajax

Ajax (Asynchronous JavaScript and XML, asynchronous JavaScript and XML) is a kind of effective use of JavaScript and DOM (Document Object Model, the document object model) operation, to achieve asynchronous communication means local Web page replacement loading. Compared with the previous synchronous communication, because it only updates a part of the page, the amount of data transmitted in the response will be reduced, the advantage is obvious.
Ajax core technology is called XMLHttpRequest API, through the JavaScript scripting language can be called and server HTTP communication. By this means, you can start the Web page has been loaded on the request, only update the local page.
and the use of Ajax in real time to get content from the server, it may lead to a large number of requests generated. In addition, Ajax has not yet solved the problems of the HTTP protocol itself.

3 – Comet

Comet is the use of the scene, when the server has content updates, the initiative to the client to send push information”. Its essence is the realization of the server side to the client push (Server Push) function through delayed response and simulation.
because usually the server receives the request, after the treatment will return a response immediately, but in order to realize the push function, Comet will first response will be placed in suspended state, when the server-side content updates, then return the response.
content can be achieved in real-time updates, but in order to save the response, the duration of a connection has become longer. In the meantime, more resources will be consumed in order to maintain connectivity. In addition, Comet has not yet solved the problems of the HTTP protocol itself.

4 – WebSocket

Using Ajax and Comet technology for communication can enhance the browsing speed of Web. But the problem is that if the use of HTTP communication protocol, it can not completely solve the bottleneck problem. Websocket network technology is a new protocol and API to solve these problems.
Websocket, the full duplex communication standard between Web browser and Web server. Once the communication connection between the Web server and the client has been established, all of the communication is based on the WebSocket protocol. Communication process can be sent to each other JSON, XML, HTML, or pictures of any format data. Because
is based on HTTP protocol, so the originator of the connection is still a client, and once established WebSocket communication connection, regardless of the server or client, any party can send messages directly to each other.

4.1 – the main features of the WebSocket protocol
  • Push function
    support push push function from server to client. In this way, the server can send data directly without having to wait for the client’s request.
  • To reduce the amount of communication
    as long as the establishment of WebSocket connection, it is hoped to keep the connection state. Compared with HTTP, not only the total cost of each connection is reduced, but also because of the small amount of information in WebSocket, the traffic is reduced correspondingly.
4.2 – WebSocket handshake procedure

WebSocket communication is mainly composed of handshake request, handshake and response two components. Handshake – request is mainly through the HTTP Upgrade field will be modified to HTTP protocol websocket protocol. Handshake – response to the client by modifying the return code 101. It is worth noting that, once the switch into the websocket protocol, URL format becomes WS and WSS began.

Rookie interview will know HTTP knowledge (five) - New Technology
WebSocket communication

5 – JSON

JSON (JavaScript Object Notation) is a lightweight data markup language based on JavaScript object representation. The types of data that can be handled are false / null / true / object / array / number / string, these 7 types.
below is a request to use JSON data format, you can see very easy to read.

Response: {"success": true "MSG": "mock success", data: "{" name ": Curry" number ": 30}, {" name ": Thompson" number ": 11}]}

Hello, I’m Binbin sauce, currently engaged in Web backend development in Tencent.
rookie will know HTTP knowledge special finishing basic knowledge on the network, we are suitable for entry-level learning, the topic now contains the following articles:
rookie will know HTTP knowledge (1) – TCP handshake protocol
rookie will know HTTP knowledge (two) – HTTP knowledge HTTP protocol (three rookie must know the characteristics of
request and response message) –
rookie will know HTTP knowledge (four) – http HTTP and HTTPS
knowledge rookie must know (five) – New Technology