What is TCP?
TCP is a connection-oriented communications protocol that facilitates the exchange of messages between computing devices in a network. TCP takes the message and splits it into packets while uniquely numbering each packet. It transmits the packets to the destination computer over the network where the protocol reassembles the message by combining the enumerated packets before handling off to the application. During the transmission of the message the connection between the two devices must remain established.
What is UDP?
Udp is a connection-less communication protocol that is message oriented, it does execute data validation but unlike tcp in case of data errors it throws away the data rather than fix the error. In addition, it doesn’t have handshake, delivery notification and back-and-forth communication between the two machines.
Differences
TCP | UDP |
Connection oriented | Connectionless |
Slower | Faster |
Uses Handshake (SYN, SYN-ACK, ACK) | Doesn’t use handshake |
Supports error checking and recovery | Only supports error checking |
Has acknowledgment segment | Doesn’t have acknowledgment segments |
TCP rearranges data packets in specific order | UDP doesn’t have fixed order, packets are independent of each other |
Header size is 20 bytes | Header size is 8 bytes |
TCP is reliable – guarantees delivery | Isnt reliable |
Supports extensive error checking | Only supports error checking via checksums |
Handles network congestion | Doesn’t handle network congestion |
Application of TCP
TCP is typically used where you need to guarantee that messages are delivered to the client and cannot afford packet loss. Typically used in organizations where reliability takes precedence over speed and where you don’t want to invest time in building reliability at the application level.
Applications of UDP
- Used by time sensitive applications where packet loss can be tolerated such as voip, online games and dns.
- Can be used for packet broadcast and multicast sending.
- Can be used in bandwidth intensive application