Difference between TCP and UDP
In networking, a protocol is a standardized way of doing certain things and formatting data so that two or more devices are able to communicate with and understand each other. Many different types of network protocols and standards are required to ensure that your computer can communicate with another computer located on the other side or half-way around the world. Most network protocol suites are viewed as structured in layers . This is a result of the OSI (Open Systems Interconnect) Reference Model designed by the ISO (International Standards Organization). The following image illustrates the place of the internet protocol in the protocol hierarchy:
Internet Protocol (IP)
The Internet Protocol (IP) is a protocol, or set of rules, for routing and addressing packets of data so that they can travel across networks and arrive at the correct destination. The TCP/IP protocol of Layer 4 (transport layer) has two protocols: TCP and UDP. TCP and UDP are not the only protocols that work on top of Internet Protocol . However, they are the most widely used. Both are protocols used for sending bits of data(known as packets) over the Internet. Also, both use port (or socket) numbers to pass information to the upper layers.
Transmission Control Protocol ( TCP ) is the most commonly used protocol on the Internet. The reason for this is because TCP offers error correction . This means that TCP is a connection oriented stream over an IP network and it guarantees that all sent packets will reach the destination in the correct order . This is due largely in part to a method called "flow control" . It determines when data needs to be re-sent, and stops the flow of data until previous packets are successfully transferred. This imply the use of acknowledgement packets sent back to the sender, and automatic retransmission , causing additional delays and a general less efficient transmission than UDP.
Characteristics of TCP
- Divides outgoing messages into segments.
- Reassembles messages at the destination station.
- Re-sends anything not received.
- Reassembles messages from incoming segments.
Examples of TCP in real life
- World Wide Web(HTTP)
- E-mail (SMTP TCP)
- File Transfer Protocol (FTP)
- Secure Shell (SSH)
User Datagram Protocol ( UDP ) is a connection-less protocol. It is faster but less reliable than TCP. The integrity is guaranteed only on the single datagram . Datagrams reach destination and can arrive out of order or don't arrive at all. It sends packets directly to a target computer, without establishing a connection first, indicating the order of said packets, or checking whether they arrived as intended. So, UDP is never used to send important data such as webpages, database information, etc. It's generally used for real time communication, where a little percentage of packet loss rate is preferable to the overhead of a TCP connection . It is important to note that UDP is only concerned with speed. This is the main reason why streaming media is not high quality.
Characteristics of UDP
- Transmit messages (called user datagrams).
- Provides no software checking for message delivery (unreliable).
- Does not reassemble incoming messages.
- Uses no acknowledgments.
- Provides no flow control.
Examples of UDP in real life
- Domain Name System (DNS)
- Streaming media applications such as movies
- Online multiplayer games
- Voice over IP (VoIP)
- Trivial File Transfer Protocol (TFTP)
Summary: TCP Vs. UDP
- TCP is connection oriented and reliable where as UDP is connection less and unreliable.
- TCP is heavy-weight, and UDP is lightweight.
- Header size is 20 bytes while UDP header size is 8 bytes.
- The speed for TCP is slower while the speed of UDP is faster.
- TCP uses handshake protocol like SYN, SYN-ACK, ACK while UDP uses no handshake protocols.
- TCP does error checking and also makes error recovery, on the other hand, UDP performs error checking, but it discards erroneous packets.
- TCP reads data as streams of bytes, and the message is transmitted to segment boundaries while UDP messages contain packets that were sent one by one. It also checks for integrity at the arrival time.
NEXT.....Modem vs. Router: What's the Difference?