http protocol (identifying data content) and webSocket protocol
Same: build on TCP, and transmit data through TCP like http
different:
The HTTP protocol is a one-way protocol, that is, the browser can only request resources from the server before the server can transmit data to the browser, and the server cannot actively transmit data to the browser. Divided into long connection and short connection, short connection requires three handshake for each http request to send its own request, and each request corresponds to a response; long connection is to keep the connection in a short time and keep TCP not disconnected, which means TCP connection.
WebSocket solves the problem of long polling that the client initiates multiple http requests to the server resource browser.
A two-way communication protocol. After a connection is established, both the WebSocket server and Browser/UA can actively send or receive data to each other, just like Socket. The difference is that WebSocket is a simple simulation based on the Web. Socket protocol;
WebSocket requires a handshake connection, similar to TCP, it also requires a handshake connection between the client and the server, and they can communicate with each other after the connection is successful.
When WebSocket establishes a handshake connection, the data is transmitted through the http protocol, "GET/chat HTTP/1.1", only some simple fields of the http protocol are used here. But after the connection is established, the actual data transmission phase does not require the participation of the http protocol.
TCP/IP protocol (used to transmit data)
Socket is an encapsulation of the TCP/IP protocol. It is not a protocol itself, but a call interface (API). Only through Socket can we use TCP/IP.
Four layers: application layer (Telnet, FTP, Email, etc.), transport layer (TCP, UDP), network layer (IP, ICMP, IGMP, etc.) and link layer (device driver)
After the three-way handshake is completed, the client and server officially begin to transmit data
Disconnect after four waves
The connection process between sockets is divided into three steps: server monitoring, client request, connection confirmation
TCP: connection-oriented, the connection is established through a three-way handshake, the connection must be disconnected when the communication is completed, only end-to-end transmission
UDP: No connection, broadcast transmission can be realized
TCP/IP communication data flow
The following is a web page we visit, the role of various agreements in it.
The above legend is from "Illustrated HTTP"