Transmission Control Protocol (TCP)
TCP is a connection-oriented protocol used by applications that require reliable data transfer. It's often compared to a phone call: before you can talk, you must establish a connection. Similarly, TCP ensures that data is delivered in the correct order, without errors or missing segments. It achieves this reliability through several key mechanisms:
- Three-Way Handshake: Before any data is sent, TCP establishes a connection between the sender and receiver. This process, known as the three-way handshake, involves three steps:
- The sender sends a SYN (synchronise) packet.
- The receiver responds with a SYN-ACK (synchronise-acknowledge) packet.
- The sender sends a final ACK (acknowledge) packet, and the connection is established. This ensures both sides are ready to communicate.
- Sequence Numbers: TCP assigns a unique sequence number to each data segment. The receiver uses these numbers to reassemble the data in the correct order. If a segment arrives out of order, the receiver can hold it until the missing segment arrives. If a segment is never received, the receiver can request a retransmission.
- Acknowledgement (ACK) Numbers: The receiver sends an acknowledgement (ACK) number back to the sender for each segment it successfully receives. This tells the sender that the data has been delivered. If the sender doesn't receive an ACK within a certain timeframe, it assumes the data was lost and retransmits it. The ACK number indicates the next segment the receiver expects to receive.
- Checksum: Both the sender and receiver calculate a checksum for each data segment. This is a mathematical value based on the segment's data. When the receiver gets a segment, it recalculates the checksum and compares it to the one sent. If they don't match, the data is considered corrupted, and the segment is discarded. This is the primary method for detecting errors.
- Flow Control: TCP also includes a mechanism for flow control to prevent the sender from overwhelming the receiver with data. The receiver can tell the sender how much data it is prepared to accept at any given time, ensuring the sender doesn't transmit faster than the receiver can process the data.
In short, TCP prioritises reliability over speed, making it ideal for applications like web browsing, email, and file transfers where data integrity is critical.
Disadvantages - above process causes latency (i.e. phone calls could become inaudible)

UDP
User Datagram Protocol (known as unrealiable)
Does not have the error handling and sequencing of TCP
Sole goal is to send data, perfect for real-time traffic
