What is the TCP/IP

TCP/IP is a layered network model consisting of a series of protocols. The following uses the four-layer model as an example. In addition to the four-layer model, there is also a seven-layer model.

TCP/IP and HTTP

In essence, TCP/IP and HTTP are not comparable. TCP/IP is a protocol family consisting of a series of protocols. HTTP is a concrete protocol, contained within TCP/IP, at the application layer, the top layer of the network hierarchy model.

TCP/IP and HTTPS

HTTPS is HTTP over SSL, which works on SSL or TSL and has encrypted communication. HTTPS adds a security layer between the application layer and transport layer to the original network layer model.

Four layer model of network

  • Application Layer This Layer contains protocols such as HTTP, FTP, and DNS. It is responsible for data assembly and defines data rules.
  • Transport Layer This Layer uses TCP and UDP protocols to establish communication connections, divide and retransmit data, and ensure stable data transmission.
  • Internet Layer This Layer has the IP protocol, sends and receives blocks of network data, addresses and routes.
  • Link Layer Data Link Layer, Ethernet, Wi-Fi.

A TCP connection

What is a connection

The communication parties confirm that they can communicate with each other without discarding each other’s information. Simply speaking, they respond to each other’s requests, that is, they connect.

Understand the relationship between TCP and HTTP

Take sending a letter. Before you send a letter, you have to make sure that the address can be received. So what’s the form of a letter? You need stamps, addresses, numbers, contents, etc… It’s a rule that allows the other party to get information. So TCP plays the role of allowing the two sides to communicate with each other, and HTTP plays the role of the rules of communication.

What is a Socket

Socket, socket, socket It is the specific implementation of TCP in the application, so the Socket connection is the TCP connection.

How does TCP establish a connection

A three-way handshake is a process used to confirm that two parties can send messages to each other.

  1. The client sends a connection request to the server.
  2. The server confirms the connection and responds to the client, ok, I’m going to send you a message too
  3. The client receives the message and confirms it to the server again

TCP close

Why do I need to close the TCP connection? In order to save resources, the application holds the information of the other party when maintaining the TCP connection, occupying memory and so on.

TCP Shutdown Procedure

Shaking hands four times is a process to confirm the end of communication between the two parties, as follows:

  1. The client says to the server, “I have no message to send to you. I want to close the transfer request from the client to the server.
  2. The server says: Ok, confirm shutdown.
  3. The server says to the client: I have no message to send to you, and will close the server-to-client transfer request.
  4. The client says: OK, confirm closing.

Why does THE TCP shutdown process need four parts

For example, the server does not send messages to the client, but the client may send messages to the server. In this case, the communication between the client and the server cannot be closed.

Confusing concept

  • HTTP connection: TCP connection over HTTP.
  • HTTP short connection: TCP connection over HTTP. Communication is closed once.
  • HTTP Long connection: TCP connection over HTTP. A connection can communicate with each other multiple times.