Difference between TCP and UDP
Alexandria University Institute of Graduate Studies and Research Department of information Technology
Difference between TCP and UDP
Prepared by : Kassem Mohammed Mostafa Student Id : 2004-3-306 E-Mail :
[email protected]
0
Difference between TCP and UDP
1. The User Datagram Protocol The User Datagram Protocol (UDP) is one of the core members of the Internet protocol suite. The protocol was designed by David P. Reed in 1980 and formally defined in RFC 768. UDP uses a simple connectionless transmission model with a minimum of protocol mechanism. It has no handshaking dialogues, and thus exposes any unreliability of the underlying network protocol to the user's program. There is no guarantee of delivery, ordering, or duplicate protection. UDP provides checksums for data integrity, and port numbers for addressing different functions at the source and destination of the datagram. With UDP, computer applications can send messages, in this case referred to as datagrams, to other hosts on an Internet Protocol (IP) network without prior communications to set up special transmission channels or data paths. UDP is suitable for purposes where error checking and correction is either not necessary or is performed in the application, avoiding the overhead of such processing at the network interface level. Time-sensitive applications often use UDP because dropping packets is preferable to waiting for delayed packets, which may not be an option in a real-time system.
2. Transmission Control Protocol The Transmission Control Protocol (TCP) is a core protocols of the Internet Protocol Suite. It originated in the initial network implementation in which it complemented the Internet Protocol (IP). Therefore, the entire suite is commonly referred to as TCP/IP. TCP provides reliable, ordered, and errorchecked delivery of a stream of octets between applications running on hosts communicating over an IP network. TCP is the protocol that major Internet applications such as the World Wide Web, email, remote administration and file transfer rely on. Applications that do not require reliable data stream service, may use the User Datagram Protocol (UDP), which provides a connectionless datagram service that emphasizes reduced latency over reliability.
3. TCP - UDP comparison
Acronym for Connection
TCP
UDP
Transmission Control Protocol
User Datagram Protocol or Universal Datagram Protocol
TCP is a connection-oriented protocol.
UDP is a connectionless protocol.
1
Difference between TCP and UDP
Function
Usage
Use by other protocols Ordering of data packets
Speed of transfer
Reliability
Header Size Common Header Fields
Streaming of data
Weight
TCP
UDP
As a message makes its way across the internet from one computer to another. This is connection based.
UDP is also a protocol used in message transport or transfer. This is not connection based which means that one program can send a load of packets to another and that would be the end of the relationship.
TCP is suited for applications that require high reliability, and transmission time is relatively less critical.
UDP is suitable for applications that need fast, efficient transmission, such as games. UDP's stateless nature is also useful for servers that answer small queries from huge numbers of clients.
HTTP, HTTPs, FTP, SMTP, Telnet
DNS, DHCP, TFTP, SNMP, RIP, VOIP.
TCP rearranges data packets in the order specified.
UDP has no inherent order as all packets are independent of each other. If ordering is required, it has to be managed by the application layer.
The speed for TCP is slower than UDP.
UDP is faster because there is no errorchecking for packets.
There is absolute guarantee that the data transferred remains intact and arrives in the same order in which it was sent.
There is no guarantee that the messages or packets sent would reach at all.
TCP header size is 20 bytes
UDP Header size is 8 bytes.
Source port, Destination port, Check Sum
Source port, Destination port, Check Sum
Data is read as a byte stream, no distinguishing indications are transmitted to signal message (segment) boundaries.
Packets are sent individually and are checked for integrity only if they arrive. Packets have definite boundaries which are honored upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent.
TCP is heavy-weight. TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control.
UDP is lightweight. There is no ordering of messages, no tracking connections, etc. It is a small transport layer designed on top of IP.
2
Difference between TCP and UDP
Data Flow Control
Error Checking
Fields
Acknowledgement Handshake Checksum
TCP
UDP
TCP does Flow Control. TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control.
UDP does not have an option for flow control
TCP does error checking
UDP does error checking, but no recovery options.
1. Sequence Number, 2. AcK number, 3. Data offset, 4. Reserved, 5. Control bit, 6. Window, 7. Urgent Pointer 8. Options, 9. Padding, 10. Check Sum, 11. Source port, 12. Destination port
1. Length, 2. Source port, 3. Destination port, 4. Check Sum
Acknowledgement segments
No Acknowledgment
SYN, SYN-ACK, ACK checksum
No handshake (connectionless protocol) to detect errors
3.1. Differences in Data Transfer Features TCP ensures a reliable and ordered delivery of a stream of bytes from user to server or vice versa. UDP is not dedicated to end to end connections and communication does not check readiness of receiver.
3.2. Reliability TCP is more reliable since it manages message acknowledgment and retr ansmissions in case of lost parts. Thus there is absolutely no missing data. UDP does not ensure that communication has reached receiver since concepts of acknowledgment, time out and retransmission are not present.
3.3. Ordering TCP transmissions are sent in a sequence and they are received in the same sequence. In the event of data segments arriving in wrong order, TCP reorders and delivers application. In the case of UDP, sent message sequence may not be maintained when it reaches receiving application. There is absolutely no way of predicting the or der in which message will be rece ived. 3
Difference between TCP and UDP
3.4. Connection TCP is a heavy weight connection r equiring three packets for a socket c onnection and handles congestion control and reliability. UDP is a lightweight transport layer designed atop an IP. There are no tracking connections or ordering of messages.
3.5. Method of transfer TCP reads data as a byte stream and message is transmitted to segment boundaries. UDP messages are packets which are sent individually and on arrival are checked for their integrity. Packets have defined boundaries while data stream has none.
3.6. How TCP and UDP work A TCP connection is established via a three way handshake, which is a process of initiating and acknowledging a connection. Once the connection is established data transfer can begin. After transmission, the connection is terminated by closing of all established virtual circuits. UDP uses a simple transmission model without implicit hand-shaking dialogues for guaranteeing reliability, ordering, or data integrity. Thus, UDP provides an unreliable service and datagrams may arrive out of order, appear duplicated, or go missing without notice. UDP assumes that error checking and correction is either not necessary or performed in the application, avoiding the overhead of such processing at the network interface level. Unlike TCP, UDP is compatible with packet broadcasts (sending to all on local network) and multicasting (send to all subscribers).
3.7. Different Applications of TCP and UDP Web browsing, email and file transfer are common applications that make use of TCP. TCP is used to control segment size, rate of data exchange, flow control and network congestion. TCP is preferred where error correction facilities are required at network interface level. UDP is largely used by time sensitive applications as well as by servers that answer small queries from huge number of clients. UDP is compatible with packet broadcast - sending to all on a network and multicasting – sending to all subscribers. UDP is commonly used in Domain Name System, Voice over IP, Trivial File Transfer Protocol and online games.
4
Difference between TCP and UDP
3.8. TCP vs. UDP for Game Servers For massively multiplayer online (MMO) games, developers often have to make an architectural choice between using UDP or TCP persistent connections. The advantages of TCP are persistent connections, reliability, and being able to use packets of arbitrary sizes. The biggest problem with TCP in this scenario is its congestion control algorithm, which treats packet loss as a sign of bandwidth limitations and automatically throttles the sending of packets. On 3G or Wi-Fi networks, this can cause a significant latency. The following criteria to choose whether to use TCP or UDP for game:
Use HTTP over TCP for making occasional, client-initiated stateless queries when it's OK to have an occasional delay.
Use persistent plain TCP sockets if both client and server independently send packets but an occasional delay is OK (e.g. Online Poker, many MMOs).
Use UDP if both client and server may independently send packets and occasional lag is not OK (e.g. Most multiplayer action games, some MMOs).
4. References
http://en.wikipedia.org/wiki/Transmission_Control_Protocol
http://en.wikipedia.org/wiki/User_Datagram_Protocol
http://www.diffen.com/difference/TCP_vs_UDP http://www.diffen.com/difference/TCP_vs_UDP\
http://www.isoc.org/INET97/proceedings/F3/F3_1.HTM
http://www.caida.org/research/traffic-analysis/tcpudpratio/
5
Difference between TCP and UDP
6
Difference between TCP and UDP
7