preface
Transmission Control Protocol (TCP) is a connection-oriented, reliable, byte stream – based transport layer communication Protocol.
HTTP and HTTPS
1. HTTP
- HTTP request process
Domain name resolution –> Initiate TCP 3-way handshake –> initiate HTTP request after establishing TCP connection –> Server ring
In response to an HTTP request, the browser gets the HTML code -> the browser parses the HTML code and requests the resources in the HTML code (such as JS, CSS, images, etc.) -> the browser renders the page to the user
- Request principle
HTTP is an application layer protocol, a C/S architecture service, based on TCP/IP protocol to communicate, listening on TCP port 80, HTTP enables the client to obtain Web resources from the server
2. HTTPS
- The principle of
HTTPS requires a handshake between the client (browser) and the server (website) before data transfer
Cryptographic information will be established for both parties to encrypt transmitted data. TLS/SSL is an encrypted transport protocol that uses asymmetric encryption, symmetric encryption, and HASH algorithms.
- Why IS HTTPS safe?
Because network requests need to be forwarded by a lot of server routers. Any intermediate node can tamper with the information, whereas if HTTPS is used, the key is between you and the terminal. HTTPS is more secure than HTTP because it uses THE SSL/TLS protocol for transmission. It includes certificate, uninstall, traffic forwarding, load balancing, page adaptation, browser adaptation, refer transfer and so on. This ensures the security of the transmission process.
What is the three-way handshake for TCP connections
1. Three handshakes
TCP is a transport layer protocol in the Internet. It uses the three-way handshake protocol to establish a connection and complete the three-way handshake between a client and a server
The server starts transmitting data.
First handshake: When establishing a connection, the client sends a SYN packet (SYN = J) to the server and enters the SYN_SENT state, waiting for confirmation from the server. SYN: Indicates the Synchronize Sequence number. Second handshake: After receiving a SYN packet, the server must acknowledge the client’s SYN (ACK = J +1) and send a SYN packet (ACK = K). In this case, the server enters the SYN_RECV state. Third handshake: After receiving the SYN+ACK packet from the server, the client sends an ACK packet (ACK = K +1) to the server. After the packet is sent, the client and the server enter the ESTABLISHED state (TCP connection is successful) and complete the three-way handshake.
2. Advantages of TCP
After receiving the packet, the peer sends a feedback. If the feedback is not received within a certain period of time, the peer automatically resends the packet due to timeout. Therefore, TCP is reliable.
3. Disadvantages of TCP
If the amount of data is relatively small, the process of establishing a connection will take up a large part, and the continuous retransmission will also cause network latency. Therefore, for example, video chat, UDP is usually used, because it is ok to lose some packets, speed and fluency are important.
Why do TCP connections require three handshakes and four waves
1. Why three handshakes?
To prevent the invalid connection request message segment from being sent to the server suddenly, an error is generated. Assume that the first connection request message segment sent by the customer stays on a network node for a long time during the two handshakes, so that it is delayed until the connection is released and reaches the server. After receiving an invalid connection request packet segment, the server considers that the client sends a new connection request. Then, the client sends a confirmation message to agree to establish a connection. At this time, the connection is established on the premise of two handshakes. This will result in wasted server resources.
2. Why four waves?
TCP is a full-duplex communication, this means that the client and server can send data to each other, so close the connection is a common behavior, both sides need to confirm the hypothesis is three waves, the direction of the first release of the client to the server connection, a TCP connection is closed at this time, then the customer can’t send the data to the server, The server can still send data to clients. If the client receives an acknowledgement message from the server, the client sends an acknowledgement message immediately, which will cause the connection to be closed while the server is still sending data to the client. In this case, the customer does not receive the entire packet segment sent by the server.
conclusion
Success often depends upon knowing how long it will take to succeed.