TCP (Transmission Control Protocol)

TCP and UDP (User Diagram Protocol) lives in layer 4 in OSI Layers.

TCP splits the data into small managable segment.

Pasted image 20230901093114.png

Each segment is marked as a sequence number. When the other device (Device B) receives these segments of data. It will sort these segments based on the sequence number:

Pasted image 20230901093200.png

Pasted image 20230901093217.png

TCP also provides error checking to make sure that the data is not corrupted.

Note:

TCP does not preseve packet boundaries. Which means by default, it automatically cut the packet into chunks no matters how big it is. For example:

Pasted image 20240912223547.png

ACK / SYNC

TCP needs ACK and SYNC. The steps are:

Pasted image 20240427125146.png

Packet Header

Pasted image 20240919203005.png

  • Source/Destination Port: source and the destination port number (not the ip address)
    • A socket = ip + port
  • Sequence number: 32 bits keep track of the order of the packet
  • Acknowledgement number: 32 bits of the next sequence number should expect
    • If the Acknowledgement number != next sequence number then the packet is marked as lost
  • HLEN (Header Length): 4 bits identify the length of the header. This is necessary because the length of Options is undefined and can be varied.
  • Reserved: Always set to 0
  • Flags: 8 1 -bit flags are used for data flow and connection control
    • The flags are:
      1. Congestion Window Reduced (CWR)
      2. ECN (Echo ECE)
      3. Urgent (URG)
      4. Acknowledgement (ACK)
      5. Push (PSH)
      6. Reset (RST)
      7. Synchronize (SYN)
      8. Final (FIN)
  • window size: 16 bit field for flow control. How many bytes sender is allowed to transmit without receiving an acknowledgement
  • Checksum: 16 bits for errordetection
  • Urgent pointer: only use when URG flag is set. This 16 bit is added to the end for urgent data
  • Options: options required by the senders process. Normally use to specify Maximum Segment Size — informs the receiver of the largest segment the sender is willing to accept