Knowledge / Computer Science and Engineering / TCP, UDP, HTTP and DNS

TCP, UDP, HTTP and DNS

Computer Science and Engineering (B.E./B.Tech) · Computer networks · free study notes for exams, placements and interviews

In short

TCP and UDP are the two transport-layer protocols that carry application data between processes, identified by port numbers; TCP is connection-oriented, reliable and flow- and congestion-controlled, while UDP is a thin, connectionless datagram service. HTTP is the request-response application protocol of the web, and DNS is the distributed naming system that maps names like www.irctc.co.in to IP addresses before any connection is made. Together they form the stack behind every web page, UPI payment, OTT stream and REST API in use in India. This is the highest-yield area of computer networks for GATE CS (TCP header fields, window and throughput numericals, handshake sequences) and for placement rounds at TCS, Infosys, Wipro, Cognizant, Amazon, Cisco, Juniper, Nutanix, Jio and Paytm, where "TCP vs UDP", "what happens when you type a URL" and "explain 3-way handshake" are near-certain questions.

Explained

Transport layer services, ports and sockets

UDP in detail

TCP: segment format and connection management

TCP reliability and flow control

TCP congestion control

HTTP

DNS

Key points

Formulas and examples

Throughput of a window protocol ≈ W / RTT, where W = window size in bits or bytes, RTT = round-trip time in seconds
Bandwidth-delay product BDP = Bandwidth (bits/s) × RTT (s) - the window needed to keep a pipe full, in bits
Utilisation of a sliding window = W / (BDP + L) where L = one frame/segment size (same units)
Smoothed RTT: SRTT = (1 − α)·SRTT_old + α·RTT_sample, with α ≈ 0.125
Deviation: RTTVAR = (1 − β)·RTTVAR_old + β·|RTT_sample − SRTT|, with β ≈ 0.25
RTO = SRTT + 4 × RTTVAR (bounded below by about 1 s in RFC 6298, and doubled on each timeout - Karn)
Slow start: cwnd after n RTTs = 2n × MSS (until cwnd ≥ ssthresh); Congestion avoidance: cwnd increases by 1 MSS per RTT
Non-persistent HTTP time for n objects ≈ 2n × RTT + transmission time; persistent ≈ (n + 1) × RTT + transmission time
Effective window at sender = min(cwnd, rwnd) − bytes in flight
Maximum TCP sequence space = 2³² bytes = 4,294,967,296 bytes (4 GiB)

Example 1 - Bandwidth-delay product and window scaling. A link between Mumbai and Singapore has bandwidth 100 Mbps and RTT 60 ms.

Example 2 - Slow start and congestion avoidance. MSS = 1 KB, initial cwnd = 1 MSS, ssthresh = 8 MSS, RTT = 100 ms. A timeout occurs just after the transmission in which cwnd = 10 MSS.

Example 3 - HTTP page load, non-persistent vs persistent. A page has 1 base HTML file and 8 small images, RTT = 50 ms, transmission time negligible, no parallel connections.

Example 4 - DNS resolution time with and without cache. A student opens www.ac.example.in. Resolver cache is empty. RTTs: client↔resolver 5 ms, resolver↔root 180 ms, resolver↔.in TLD 60 ms, resolver↔authoritative 30 ms.

Example 5 - Sequence and acknowledgement numbers. A client's ISN is 1,000; the server's is 5,000. The client then sends 500 bytes, and the server replies with 1,200 bytes.

FeatureTCPUDP
ConnectionConnection-oriented (handshake)Connectionless
Header size20-60 bytes8 bytes
ReliabilityACKs, retransmission, orderingNone
Flow controlYes (advertised window)No
Congestion controlYes (AIMD, slow start)No
Data modelByte stream, no boundariesDatagram, boundaries kept
Broadcast/multicastNot supportedSupported
Speed / overheadSlower, higher overheadFaster, minimal overhead
Typical useHTTP, HTTPS, SMTP, FTP, SSHDNS, DHCP, VoIP, gaming, streaming, QUIC
AspectHTTP/1.1HTTP/2HTTP/3
TransportTCPTCPQUIC over UDP
FormatTextBinary framesBinary frames
ConcurrencyMultiple TCP connectionsMultiplexed streamsMultiplexed streams, independent loss recovery
Header compressionNoneHPACKQPACK
Head-of-line blockingAt HTTP and TCP levelAt TCP level onlyLargely eliminated
# Checking all four protocols from a terminal
dig +trace www.iitb.ac.in          # full iterative path: root -> .in -> authoritative
nslookup -type=MX iitbombay.org    # mail exchanger records
curl -I https://www.india.gov.in   # HTTP response headers and status line
ss -tan | grep -c ESTAB            # count established TCP connections
tcpdump -n 'tcp[tcpflags] & tcp-syn != 0'   # capture handshake SYNs

Where it is used

Interview questions

Common mistakes

Related topics

OSI and TCP/IP models · IP addressing and subnetting · Socket programming · Network security: firewalls, VPN and IDS · Routing algorithms and protocols · Data link layer: framing, error control and MAC

Open in the Knowledge reader →Find jobs →