TCP I like to think of as certified mail. The data is sent, and you receive a receipt confirming that it was received.
- Connection Oriented Protocol
- TCP requires a three way handshake to establish a conversation with the receiving end.
- The Three Way Handshake Looks like This.
- The Sender will send a SYN (Sync)
- The Receiver will respond with a SYN-ACK (Sync-Acknowledgement)
- The Sender will respond with an ACK (Acknowledgement)
- Now the connection will be established and traffic can be sent.
- Error Checking
- A checksum field is included within each segment of data which is used to validate the data.
- Error Recovery
- The receiver will request you resend data if the data received fails a checksum and is determined to be corrupt.
- Data Sequencing
- The packets of the transmission are numbered in order
- The receiver will request you resend data if its not received
- The receiver knows how to put the data back together thanks to the sequencing
- Because of the above features delivery is guaranteed.
- Also because of the above features it is slower than UDP.
- Best used browsing websites, Emails, downloading files; really anything where a single corrupt packet will make a file unusable, like a word document.
UDP is more like traditional mail where you send it and hope it arrives.
- Connectionless Protocol
- UDP doesn't have a handshake, and does not require an established connection
- Error Checking
- A checksum field is used here as well
- If the checksum fails then UDP will simply discard the packet
- Data Sequencing
- There is no sequencing used. The application layer will have to be the brains if sequencing is required.
- Delivery of all data is not guaranteed
- Because so much of the "fixing" of the data is skipped, UDP is much faster than TCP.
- Best used for DNS, DHCP, Voice and Video.
TCP | UDP |
---|---|
connection-oriented protocol. | connectionless protocol. |
Uses a three-way handshake: SYN, SYN-ACK, ACK | No handshake |
Traffic goes in both directions | Traffic goes in only one direction |
Provides error checking | Provides no error checking. |
Slower speeds due to error recovery | UDP is faster since there is no error recovery |
Header size: 20 bytes | Header size: 8 bytes. |
Performs error checking, and requests a resend if bad packet rcvd. | Performs error checking, and discards bad packets |
Provides guaranteed, reliable transmission of data to the destination | Does not guarantee transmission of all packets |
Acknowledgment segments | No Acknowledgment segments |