Skip to main content
โšก Calmops

Understanding Network Protocols: TCP, UDP, HTTP

Introduction

Network protocols are the foundation of internet communication. Understanding how data moves across networks helps you build better applications and troubleshoot issues. This guide covers essential network protocols.

OSI Model

Seven Layers

Layer Protocol Examples
7. Application HTTP, DNS Browser, email
6. Presentation TLS, SSL Encryption
5. Session RPC, NetBIOS Session management
4. Transport TCP, UDP Port-to-port
3. Network IP, ICMP Router-to-router
2. Data Link Ethernet, WiFi Frame delivery
1. Physical Fiber, Cable Bits over wire

Transport Layer

TCP vs UDP

Feature TCP UDP
Connection Yes No
Reliability Reliable Best effort
Order Guaranteed Not guaranteed
Speed Slower Faster
Overhead More Less

When to Use

  • TCP: Web, email, file transfer (reliability)
  • UDP: Video streaming, gaming, DNS (speed)

TCP Handshake

Client โ†’ SYN โ†’ Server
Client โ† SYN-ACK โ† Server
Client โ†’ ACK โ†’ Server

HTTP/HTTPS

HTTP Methods

Method Description Idempotent
GET Read Yes
POST Create No
PUT Replace Yes
PATCH Modify No
DELETE Remove Yes

HTTP Status Codes

1xx: Informational
2xx: Success
3xx: Redirection
4xx: Client Error
5xx: Server Error

Common codes:

  • 200 OK
  • 201 Created
  • 301 Moved Permanently
  • 400 Bad Request
  • 401 Unauthorized
  • 404 Not Found
  • 500 Internal Server Error

HTTPS

# TLS handshake
Client โ†’ ClientHello โ†’
โ† ServerHello + Certificate โ†
โ†’ Key Exchange โ†’
โ† Finished โ†
Encrypted communication begins

TLS/SSL

  • Encrypts data in transit
  • Server authentication
  • Data integrity
  • Uses certificates

DNS

How DNS Works

1. Browser asks: "What is example.com?"
2. Local DNS resolver checks cache
3. Root server: "Ask .com TLD server"
4. TLD server: "Ask authoritative server"
5. Authoritative server: "IP is 93.184.216.34"

DNS Records

Type Purpose
A IPv4 address
AAAA IPv6 address
CNAME Alias
MX Mail server
TXT Text info
NS Name server

Common Protocols

FTP

File Transfer Protocol:

  • Port 21 (control)
  • Port 20 (data)
  • Commands: GET, PUT, LIST

SSH

Secure Shell:

  • Port 22
  • Encrypted remote access
  • SFTP, SCP

SMTP

Simple Mail Transfer Protocol:

  • Port 25, 587
  • Send email between servers

IMAP/POP3

  • IMAP (143/993): Server-based
  • POP3 (110/995): Download and delete

Ports

Common Ports

Port Service
21 FTP
22 SSH
25 SMTP
53 DNS
80 HTTP
443 HTTPS
3306 MySQL
5432 PostgreSQL
6379 Redis

Ephemeral Ports

  • 32768-60999 (typically)
  • Used for client-side connections

Troubleshooting

Tools

  • ping: Check reachability
  • traceroute: Path to destination
  • netstat: Connection status
  • tcpdump/Wireshark: Packet analysis
  • dig/nslookup: DNS queries

Common Issues

  • DNS resolution failure
  • Firewall blocking
  • Port not open
  • High latency

Security

Common Attacks

  • DDoS: Flooding with requests
  • Man-in-the-middle: Intercepting traffic
  • DNS spoofing: Fake DNS responses

Best Practices

  • Use HTTPS
  • Firewall rules
  • Keep software updated
  • Monitor traffic

Conclusion

Understanding network protocols helps you build better applications and diagnose issues. Start with TCP vs UDP, learn HTTP thoroughly, and understand DNS. These fundamentals apply everywhere.


Resources

Comments