Вы находитесь на странице: 1из 5

1.

2- Compare & Contrast TCP and UDP Protocol


There are two types of Internet Protocol (IP) traffic. They are TCP or Transmission Control Protocol and
UDP or User Datagram Protocol. TCP is connection oriented – once a connection is established, data can
be sent bidirectional. UDP is a simpler, connectionless Internet protocol. Multiple messages are sent as
packets in chunks using UDP.

Comparison chart
Difference:-

TCP UDP
User Datagram Protocol or Universal
Acronym for Transmission Control Protocol
Datagram Protocol
TCP is a connection-oriented
Connection UDP is a connectionless protocol.
protocol.
UDP is also a protocol used in
message transport or transfer. This is
As a message makes its way across
not connection based which means
Function the internet from one computer to
that one program can send a load of
another. This is connection based.
packets to another and that would be
the end of the relationship.
UDP is suitable for applications that
TCP is suited for applications that need fast, efficient transmission, such
require high reliability, and as games. UDP's stateless nature is
Usage
transmission time is relatively less also useful for servers that answer
critical. small queries from huge numbers of
clients.
Use by other DNS, DHCP, TFTP, SNMP, RIP,
HTTP, HTTPs, FTP, SMTP, Telnet
protocols VOIP.
UDP has no inherent order as all
Ordering of data TCP rearranges data packets in the packets are independent of each
packets order specified. other. If ordering is required, it has to
be managed by the application layer.
UDP is faster because error recovery
The speed for TCP is slower than
Speed of transfer is not attempted. It is a "best effort"
UDP.
protocol.
TCP UDP
There is absolute guarantee that the
There is no guarantee that the
data transferred remains intact and
Reliability messages or packets sent would reach
arrives in the same order in which it
at all.
was sent.
Header Size TCP header size is 20 bytes UDP Header size is 8 bytes.

Packets are sent individually and are


Data is read as a byte stream, no
checked for integrity only if they
distinguishing indications are
Streaming of data arrive. Packets have definite
transmitted to signal message
boundaries which are honored upon
(segment) boundaries.
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 UDP is lightweight. There is no


three packets to set up a socket ordering of messages, no tracking
Weight
connection, before any user data can connections, etc. It is a small
be sent. TCP handles reliability and transport layer designed on top of IP.
congestion control.

TCP does Flow Control. TCP


requires three packets to set up a UDP does not have an option for flow
Data Flow Control
socket connection, before any user control
data can be sent. TCP handles
reliability and congestion control.

TCP does error checking and error UDP does error checking but simply
Error Checking recovery. Erroneous packets are discards erroneous packets. Error
retransmitted from the source to the recovery is not attempted.
destination.

1. Sequence Number, 2. AcK


number, 3. Data offset, 4. Reserved, 1. Length, 2. Source port, 3.
Fields
5. Control bit, 6. Window, 7. Urgent Destination port, 4. Check Sum
Pointer 8. Options, 9. Padding, 10.
Check Sum, 11. Source port, 12.
Destination port
Acknowledgement Acknowledgement segments No Acknowledgment
No handshake (connectionless
Handshake SYN, SYN-ACK, ACK
protocol)
TCP UDP

Similarities :-
Source port,
Source port, Destination port, Check
Destination port,
Common Header Fields Sum
Check Sum

Contents: TCP vs UDP


 1 Differences in Data Transfer Features
o 1.1 Reliability
o 1.2 Ordering
o 1.3 Connection
o 1.4 Method of transfer
o 1.5 Error Detection
 2 How TCP and UDP work
 3 Different Applications of TCP and UDP
o 3.1 TCP vs. UDP for Game Servers
 4 References

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.

Reliability

TCP is more reliable since it manages message acknowledgment and retransmissions 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.
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 order in which message will be
received.

Connection

TCP is a heavy weight connection requiring three packets for a socket connection 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.

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.

Error Detection

UDP works on a "best-effort" basis. The protocol supports error detection via checksum but
when an error is detected, the packet is discarded. Retransmission of the packet for recovery
from that error is not attempted. This is because UDP is usually for time-sensitive applications
like gaming or voice transmission. Recovery from the error would be pointless because by the
time the retransmitted packet is received, it won't be of any use.

TCP uses both error detection and error recovery. Errors are detected via checksum and if a
packet is erroneous, it is not acknowledged by the receiver, which triggers a retransmission by
the sender. This operating mechanism is called Positive Acknowledgement with Retransmission
(PAR).

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).
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.

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.

Experienced developer Christoffer Lernö weighed the pros and cons and recommends the
following criteria to choose whether to use TCP or UDP for your 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).

Вам также может понравиться