This is the 7th day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021.

1. Protocols at the transport layer

  • The transport layer provides session and packet communication services for the application layer.
  • The transport layer assumes the responsibilities of the OSI transport layer.
  • The core protocols of the transport layer are TCP and UDP.

2. Differences between TCP and UDP

    1. TCP is connection-oriented (for example, a dialup is required to establish a connection before making a phone call). UDP is connectionless, that is, no connection is required before sending data.
    1. TCP provides reliable services. That is, data transmitted over a TCP connection is error-free, not lost, not duplicated, and arrives in sequence. UDP does its best to deliver, but does not guarantee reliable delivery.
    1. TCP Byte – oriented stream. UDP is packet oriented.
    1. UDP does not have congestion control, so network congestion does not slow down the sending rate of the source host (useful for real-time applications, such as IP telephony and real-time video conferencing).
    1. TCP connections can only be point-to-point. UDP connections support one-to-one, one-to-many, many-to-one, and many-to-many interactive communications.
    1. The logical communication channel of TCP is full duplex reliable channel. UDP is an unreliable channel.

3. Advantages and disadvantages of TCP and UDP

TCP has the following advantages: Data transmission is reliable and stable, and data sequence is correct. TCP has the following disadvantages: Slow data transmission, low efficiency, high system resource occupation, and vulnerability. Advantages of UDP: Fast data transmission, relatively secure than TCP. Disadvantages of UDP: data transmission is unreliable, unstable, and not guaranteed sequence.

When should YOU use UDP? When the network communication quality is not high and the network communication speed is required, UDP can be used. For example: voice, video, etc.

4. TCP

4.1 FEATURES of TCP

TCP is the Transmission Control Protocol (TCP), which provides reliable, connection-oriented, byte stream oriented network data Transmission services.

4.2 TCP Connection-oriented

TCP is a connection-oriented protocol. A total of seven steps are required to establish and disconnect a connection, including three handshake attempts to establish a connection and four handshake attempts to disconnect a connection.

4.3 Three-way Handshake to Establish a connection

    1. The client first asks the server to open a port (using TCP packets with SYN segment 1).
    1. The server then sends an ACK packet to notify the client that the request packet has been received
    1. After receiving the acknowledgement packet, the client sends another acknowledgement packet to confirm the acknowledgement packet sent by the server

The connection is established, also known as the TCP three-way handshake. If you want both sides to get better, you must send three messages, and only three messages are needed.

Q: What is three handshakes, not two?

To solve the problem of timeout causing duplicate setup. Why: There are problems with two handshakes. When the client sends a SYN request to establish a connection, the client repeatedly sends a SYN message after the network delay times out. After receiving the second request, the server replies with a confirmation message, indicating that the connection is established. After the initial SYN connection request reaches the server, the server thinks that the client wants to establish a new connection and sends a reply again. This leads to repeated connections.

4.4 Disconnection with wave four times

The TCP connection is a full-duplex (sending and receiving at the same time) connection. Therefore, before closing the connection, you must close the connection in both directions.

    1. The client sends a TCP packet with FIN 1 to disable data transmission from the client to the server
    1. After receiving the FIN, the server sends an ACK packet to the client.
    1. The server closes the client connection and sends a FIN to the client.
    1. The client sent an ACK packet for confirmation. Procedure

So the connection is disconnected. This process is also known as TCP’s four waves. Question: Why four waves?

TCP connections are full-duplex connections. Therefore, a TCP connection is closed only when it is closed bidirectionally. The client sends a FIN request to sever the connection, and the server sends an ACK response to sever the connection. The connection is half-closed. The server sends a FIN request to the client to sever the connection, and the client replies with an ACK to close the connection.

5. Add

  • Full Duplex: The ability to send and receive data simultaneously, much like on a phone, and hear each other while speaking. Current network cards generally support full duplex.
  • Half Duplex, Half Duplex) : the so-called Half Duplex is refers to a period of only a movement, a simple example, a narrow road, at the same time can only have one car, when there are two cars off, this situation can only be a first, after all the other cars to open, this example illustrates the principle of Half Duplex. Early walkie-talkies and early hubs were based on half-duplex products.
  • Simplex communication refers to the transmission of data over a communication line in a single direction.