Created by ChatGPT o3

This concise primer refreshes the IP → UDP/TCP → NAT layers you’ll use constantly while building a peer‑to‑peer calling app.


1. Internet Protocol (IP)

1.1 Packets & Addressing

  • IPv4: 32‑bit addresses (e.g. 192.168.1.42). About 4.3 billion total, now scarce.
  • IPv6: 128‑bit addresses (e.g. 2001:0db8::1). Practically inexhaustible.
  • Packet = header (metadata) + payload (upper‑layer data).
  • IP is connectionless and best‑effort: no guarantees on delivery order, timing, or integrity.

1.2 Fragmentation

If a packet exceeds the network’s MTU (~1500 bytes on Ethernet), routers may split it into fragments—bad for real‑time media (extra delay & loss risk). Keep RTP payloads small.

1.3 Port Numbers

Ports live in UDP/TCP, not IP, but many tools show them together (e.g., 192.0.2.10:3478).


2. Transport Layer Choices

FeatureUDPTCP
Connection setupNone (stateless)3‑way handshake (SYN/ACK)
ReliabilityNone—packets may drop or reorderBuilt‑in ACKs, retransmission
OrderingNot guaranteedGuaranteed (byte stream)
OverheadLow (8‑byte header)Higher (20‑byte header + control flags)
Latency impactMinimalCan spike (Nagle’s algorithm, congestion control)
Typical uses in VoIPRTP media, STUN, DTLS‑SRTPSIP over TCP/TLS, WebSocket signalling

Takeaway: Real‑time audio/video prefers UDP—lost frames are cheaper than late ones. Signalling prefers TCP—small, reliable.

2.1 RTP over UDP

RTP rides atop UDP. RTP adds sequence numbers & timestamps so receivers can re‑sequence and sync playback.

2.2 TCP & TLS for Signalling

SIP can run on UDP, TCP, or TCP+TLS. WebRTC browsers usually tunnel signalling JSON over WebSocket (TCP) to traverse firewalls cleanly.


3. Network Address Translation (NAT)

3.1 Why NAT Exists

  • Preserve scarce IPv4 addresses.
  • Mask internal topologies for security.

3.2 How It Works

A home router keeps a translation table mapping:

private_IP:private_port  ⇄  public_IP:public_port

Outgoing packets rewrite the source. Inbound replies must hit the exact 5‑tuple or they’re dropped.

3.3 NAT Types (RFC 4787)

TypeMapping StabilityFiltering StrictnessVoIP Impact
Full ConeFixed portLooseEasiest
RestrictedFixed portIP‑restrictedOK
Port‑RestrictedFixed portIP+port restrictedTougher
SymmetricNew port per destStrictHard—needs TURN

3.4 Traversal Tools

  1. STUN – learn your public IP/port (works unless symmetric NAT).
  2. ICE – gather candidates (host, srflx, relay) and perform connectivity checks.
  3. TURN – relay packets when P2P fails; last resort.

3.5 Voice Quality vs NAT

Each extra hop adds latency. TURN adds ~30–50 ms RTT in a local network; keep the relay as close as possible or avoid it.


4. Quick Checklist Before Coding

Master these basics and the SIP/WebRTC layers in your course will feel much easier.