You are on page 1of 23

TCP v/s UDP

PRASHANTH V GALAGALI
PES UNIVERSITY
Types of Data Deliveries

(Host to host)

(Process to process)
TRANSPORT
LAYER

TCP UDP
UDP - User Datagram Protocol
 Used mainly for one way, short communications
 datagrams don’t contain information about other packets
 Each packet independent of each other
 Messages can be no larger than the max UDP packet size
TCP/IP (Transmission Control
Protocol/Internet Protocol)

 Connection-oriented service modelled after the telephone system.


To talk to someone, pick up a phone, dial the number, talk and disconnect.
 Similarly, in a network, the service user will
 Establish a connection
 Use the connection
 Release the connection
 The sender, receiver and the network may conduct a negotiation about data
transfer speed, maximum message size, etc
Different Applications of TCP and UDP
 Web browsing, email and file transfer are common applications.
 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
 multicasting – sending to all subscribers.
 UDP is commonly used in Domain Name System, Voice over IP, Trivial File
Transfer Protocol and online games.
TCP
Developing
networking
Games….????
UDP
Non
Action
action
Games Like World
games
of Like MMO
warcraft

Use UDP Use TCP


WHY….??????
Game servers: UDP vs TCP
by Christoffer Lernö
WHAT TCP MEANS IN PRACTICE
 Straightforward persistent connections
 Reliable messaging
 Arbitrarily sized packets
 Anyone with hands-on experience with TCP knows that a solid implementation needs to
handle many not-so-obvious corner cases, such as disconnect detection, packet congestion
due to slow client response.

BUT
 Despite the up-front ease of use, a good TCP solution isn’t easy to code.
If so, then why not UDP….????
 single socket for communication – unlike TCP which require a socket for each
connected client.
 However, for most situations you actually need some concept of a connection,
some rudimentary ordering and often also reliability.

DID U KNOW….!!!!

Just because TCP is connection oriented it can handle 100+


simultaneous connections.
THE FLAWED CASE FOR TCP
So why does World of Warcraft work with TCP?

OOPS…..SORRY ITS

“why does World of Warcraft work despite the occasional 1000+ms delay?”.
 Because that is the reality of TCP – on dropped packets you’ll get huge lags as
TCP first needs to detect the missing packet, then resend the packet all while
cutting down throughput.

Before the packets drop.


i.e Normal bandwidth
After the packets drop
i.e Bandwidth is reduced
How does it happen with TCP protocol…??

 This property is achieved because the IP protocol is written on top of the TCP
protocol.

TCP/IP PROTOCOL
DOES UDP ALSO SUPPORT THIS FEATURE…????
 Reliable UDP will also have a delay.
 but since it’s a property of whatever protocol you write on top of UDP, it’s possible
to reduce delays in many ways .
So why does World of Warcraft (and other
games) work with these delays?
 It’s simply because they’re able to hide the latency.
 In the case of World of Warcraft, there are no player-to-player collisions.
 Such collisions can’t be handled reliably predicted – but player-to-environment
can, so the latter works fine with TCP.

Command_a(exp1)

Command_b(exp1,exp2)
 Command_a(target)

Command_b(target,fire)
What actually happens with command..???

 When the command_a is executing then already the “target” packet would
have arrived.
 When the comman_b is executed then, only the “fire” packet would have
been arrived.
 Thus in this way TCP protocol controls the traffic congestion.
Does TCP not fail at all…!!!
 Player vs player(multi-player) action games often fall into this category.

How does it happen……????


 Due to certain game rules and to prevent cheating, the server can only reveal information
about the character’s immediate surroundings.

 Everything went fine with LAN internet connection, but problem occurs with the WiFi.

 Writing a few test programs showed the WiFi occasionally dropping packets, and every time
that happened, server response time shot up from 100-150 ms to 1000-2000 ms.
Then when to use UDP….???

 We replaced the TCP code with a custom reliable UDP implementation which
cut the penalty of a lost packet down to an additional 50 ms(!) – less than the
time of a complete roundtrip.
 And that was only possible due having complete control of the reliability layer
on top of UDP.
So UDP or TCP?

 Use HTTP over TCP - 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).

You might also like