TCP control

TCP control (connection establishment)

 In TCP communication, the CodeBit in the TCP header has an important meaning. The TCP header looks like this:

 The communicating party sends a segment with the code bit SYN flag set to "1" to the other party. If the receiving side can communicate, it responds with a segment with the SYN flag set to "1" as well. If communication is not possible, a segment with the RST flag set to "1" is returned.

In this exchange, packets with no data, just TCP headers are exchanged.

The connection is established when both sides click "OK".

 This completes the transmission path for sending and receiving each other's segments. This transmission line is called a virtual circuit. This line is maintained until communication ends or is cut off for some reason, and is used for subsequent packet exchanges.

TCP control (sending and receiving data)

 When a TCP connection is established and a virtual circuit is created, data transmission/reception begins. The data sender sends segments of the amount of data indicated by the window size in the TCP header.

 Window size is used for flow control in TCP communication. The window size determines how many segments can be sent at once. TCP performs flow control by controlling the number of segments sent and received at one time.

* The window size refers to the amount of the opponent's buffer

The other party that receives the segment examines the received segment for corruption.

 It calculates the checksum of the received segment, compares it with the checksum value in the TCP header, and if it matches, it is not corrupted. Also check the sequence numbers to see which segments have arrived and which have not.

 If the receiver successfully receives the data, it sends a response segment to the sender. The sender checks the response segment of the returned response message and prepares to send the next segment.

 If a response segment is not returned to the sender within a certain period of time, the sender determines that the transmission has failed and resends the segment. By doing so, you are dealing with transmission errors.

 Please note that the segment is not repaired by looking at the checksum. TCP handles transmission errors by retransmitting segments.

TCP control (disconnect line)

Termination of communication in TCP includes the following cases.

  • end of data transmission
  • Forced line disconnection

end of data transmission

When the sender runs out of data to send, it sends a segment with the code bit FIN flag set to '1'.

 If the other side also has no data to send, it returns a segment with the FIN flag set to "1". After that, the virtual circuit will be disconnected.

*Actually, the sender sets the ACK flag at the end, sends a segment with "sequence number + 1", and the connection ends.

 In the TCP close process, the close process is completed only after notifying each other that there is no more data to send. Just stopping reception unilaterally does not result in correct close processing.

Forced line disconnection

In TCP, to ensure the reliability of data transmission, we monitor the return of ACK for the transmitted data.

 If an ACK reply is not received within a certain period of time, the transmission will be repeated again. If ACK is not returned even after resending a certain number of times, a segment with the RST flag of the code bit set to "1" is sent, and the connection is forcibly terminated.

 Here, for the sake of simplification of the explanation, a forced disconnection is performed after 3 repeated failures, but there are various methods for determining the monitoring time and the number of retransmissions.