preface

TCP packet segment structure



Three-way handshake



The Chinese teacher explained it like this:

  • The client sends a connection request to the server: SYN packet segment: (SYN=1, SEq =x)
    • SYN=1: establishes the connection request control segment
    • Seq =x: indicates that the sequence number of the first byte of the transmitted packet segment is X, and this sequence number represents the sequence number of the entire packet segment. The client enters SYN_SEND
  • After receiving a TCP connection request segment, the server sends an acknowledgement packet (SYN=1,ACK=1, SEq =y, ACK_seq =x+1).
    • SYN=1: indicates the confirmation segment that agrees to establish a new connection
    • Ack_seq =x+1: indicates that the system has received the packet segment with the SERIAL number x and is ready to receive the packet segment with the serial number X +1
    • Seq =y: The server tells the customer to confirm that the sequence number of the first data byte in the packet segment is Y
    • The server enters SYN_RCVD with LISTEN
  • The client confirms the consent connection segment of the server: (ACK=1, SEq =x+1, ACK_seq =y+1)
    • Seq = X +1: The sequence number of the first data byte in the packet segment transmitted by the customer is X +1
    • Ack_seq = Y +1: The customer expects to receive the packet segment with the SEQUENCE number y+1 from the server.
    • When the client sends the ACK, the client enters the ESTABLISHED state
    • When the service receives an ACK, it also enters the ESTABLISHED state (only the third handshake can carry data).

My Chinese score is not good, so I explain:

  • M: Are you free today?
  • W: I’m free today
  • M: What do you think of this shop? I sent you, I think it’s good, let’s go eat!

Four times to wave



The Chinese teacher explained it like this:

  • The client sends a connection release packet to the server :(FIN=1,seq=u)
    • FIN=1 on the header: the sender of the TCP packet ends sending data and requests to release the connection
    • Serial number seq= U: indicates that the serial number of the first data byte is U
    • The client state changes from ESTABLISHED to FIN_WAIT_1 (end wait 1 state)
  • The server sends the confirmation segment to the client :(ACK=1,seq=v,ack_seq=u+1)
    • ACK=1: indicates that the confirmation field is valid
    • Confirmation number ACK_seq = U +1: indicates that the server expects to receive the customer’s data package whose serial number is U +1
    • Seq = V: Indicates that the serial number of the first data byte transmitted by the server is V
    • The server state changes from ESTABLISHED to CLOSE_WAIT
    • After receiving the ACK segment, the client enters FIN_WAIT_2 from FIN_WAIT_1
  • The server sends a connection release packet to the client: FIN=1,ACK=1, SEq = W, ACK_SEq = U +1
    • FIN=1: Requests to release the connection
    • ACK=1: indicates that the confirmation field is valid
    • Confirmation number ACK_seq = U +1: indicates that the server expects to receive the customer’s data package whose serial number is U +1
    • Seq =w: indicates that the serial number of the first data byte is w. The server status changes from CLOSE_WAIT to LAST_ACK (the last confirmation status).
  • Client sends confirmation segment to server :(ACK=1,seq=u+1,ack_seq=w+1)
    • ACK=1: indicates that the confirmation field is valid
    • Confirm serial number ACK_seq = W +1: indicates that the customer expects to receive the packet with serial number W +1 from the server
    • Seq = U +1: Indicates that the serial number of the first data byte transmitted by the customer is U +1
    • The client status changes from FIN_WAIT_2 to TIME_WAIT. After waiting for 2MSL, the client enters the CLOSED state to release the connection
    • After receiving the last ACK segment, the server uses LAST_ACK to enter CLOSED and release the connection

My Chinese score is not good, so I explain:

  • Man: Baby, I have to go now
  • W: No, I’m still applying a facial mask. Stay with me for a while
  • W: I’m ready. You can go now
  • M: I can’t bear to hang up. Go ahead
  • W: Well, I’ll go then
  • M: I heard a beep hanging up after waiting for 2MSL

Refer to the link

Github.com/Advanced-Fr…