HLD1:Computer Networks Notes

작성자

카테고리:

← 피드로
DEV Community · Shifa · 2026-07-28 개발(SW)

A beginner-friendly and interview-ready guide to Client-Server Architecture, P2P, Protocols, TCP/UDP, WebSockets, and WebRTC.

Table of Contents

Communication Models

1. Client-Server Architecture

In the Client-Server model, a client sends a request to a central server, and the server processes the request before sending back a response.

           +-----------+
           |  Server   |
           +-----------+
            /    |    \
           /     |     \
          /      |      \
 +---------+ +---------+ +---------+
 | Client1 | | Client2 | | Client3 |
 +---------+ +---------+ +---------+

Enter fullscreen mode Exit fullscreen mode

Workflow

  1. Client sends Request
  2. Server processes Request
  3. Server returns Response

Examples

  • Google
  • Amazon
  • Facebook
  • Gmail
  • Banking Applications

Key Points

  • Centralized architecture
  • Clients cannot communicate directly
  • Every request passes through the server

2. Peer-to-Peer (P2P)

In Peer-to-Peer architecture, devices communicate directly with one another.

      Peer A
      /    \
     /      \
Peer B ---- Peer C

Enter fullscreen mode Exit fullscreen mode

Examples

  • WebRTC
  • Torrent

Key Points

  • No central server for media transfer
  • Direct communication between peers
  • Lower latency

Protocols

A protocol is a set of rules that defines how data is transmitted between devices.

HTTP (HyperText Transfer Protocol)

Purpose

Used for loading websites and REST APIs.

Features

  • Request → Response
  • Stateless
  • Runs over TCP
  • Client always starts communication
Browser --------HTTP Request--------> Server
Browser <-------HTTP Response-------- Server

Enter fullscreen mode Exit fullscreen mode

Used In

  • Websites
  • REST APIs
  • Login Systems
  • Web Applications

FTP (File Transfer Protocol)

Purpose

Transfers files between client and server.

FTP uses Two Connections

1. Control Connection

  • Login
  • Commands
  • Authentication

2. Data Connection

  • File Upload
  • File Download
Client

│
├── Control Connection ─────────► Server
│
└── Data Connection ────────────► Server

Enter fullscreen mode Exit fullscreen mode

Why Two Connections?

Commands and file data are transferred separately, making file transfer easier and more efficient.

SMTP (Simple Mail Transfer Protocol)

Purpose

Used to Send Emails.

Sender

↓

SMTP

↓

Mail Transfer Agent (MTA)

↓

Receiver Mail Server

Enter fullscreen mode Exit fullscreen mode

Key Points

  • Only sends emails
  • Uses TCP

IMAP (Internet Message Access Protocol)

Purpose

Used to Read, Access and Synchronize Emails.

Mail Server

↓

IMAP

↓

Email Client

Enter fullscreen mode Exit fullscreen mode

Key Points

  • Reads emails
  • Synchronizes emails across multiple devices
  • Emails remain stored on the server

WebSocket

Purpose

Provides Real-Time Two-Way Communication.

Unlike HTTP, both client and server can send messages whenever they want.

Client 1
    ▲
    │
    ▼
+-----------+
|  Server   |
+-----------+
 ▲    ▲    ▲
 │    │    │
 ▼    ▼    ▼
C2   C3   C4

Enter fullscreen mode Exit fullscreen mode

Important

  • NOT Peer-to-Peer
  • Client ↔ Server
  • Full Duplex Communication
  • Persistent Connection

Clients cannot communicate directly.

The server forwards messages between clients.

Examples

  • WhatsApp Web
  • Live Chat
  • Multiplayer Games
  • Notifications
  • Stock Market Updates

WebRTC (Web Real-Time Communication)

Purpose

Allows direct Peer-to-Peer communication.

Peer A  <──────────────►  Peer B

Enter fullscreen mode Exit fullscreen mode

Uses

  • Video Calls
  • Voice Calls
  • Screen Sharing

Important

  • Mostly uses UDP
  • Optimized for low latency
  • Supports audio, video and data channels

Network Layers

Only the important layers are shown.

+-----------------------+
| Application Layer     |
+-----------------------+
| Transport Layer       |
+-----------------------+
| Network Layer         |
+-----------------------+

Enter fullscreen mode Exit fullscreen mode

Application Layer

Contains protocols like:

  • HTTP
  • FTP
  • SMTP
  • IMAP
  • WebSocket

Transport Layer

Responsible for

  • Reliability
  • Speed
  • Packet Delivery

Protocols

  • TCP
  • UDP

Network Layer

Responsible for

  • Routing
  • IP Addressing

Uses IP Addresses to send packets between devices.

TCP (Transmission Control Protocol)

TCP is a Connection-Oriented protocol.

Before sending data, TCP establishes a connection.

Working

Connection Established

↓

Data Split into Packets

↓

Sequence Numbers Added

↓

Packets Sent

↓

Receiver Sends ACK

↓

Missing Packets Retransmitted

Enter fullscreen mode Exit fullscreen mode

Features

  • Reliable
  • Ordered Delivery
  • Acknowledgement (ACK)
  • Retransmission
  • Error Detection
  • Connection-Oriented

Used In

  • HTTP
  • FTP
  • Email
  • Banking
  • Downloads

When to Use TCP

Whenever every packet is important and must arrive in the correct order.

UDP (User Datagram Protocol)

UDP is a Connectionless protocol.

Working

Packet 1

Packet 3

Packet 2

Packet 5

Enter fullscreen mode Exit fullscreen mode

Packets may arrive in any order.

Features

  • No Connection Setup
  • No ACK
  • No Retransmission
  • Best Effort Delivery
  • Very Fast

Used In

  • Live Streaming
  • Video Calls
  • Voice Calls
  • Online Games
  • DNS

When to Use UDP

When speed is more important than perfect reliability.

Example:

During a video call, losing one frame is acceptable, but waiting for retransmission would introduce lag.

TCP vs UDP

Feature TCP UDP Connection ✅ Yes ❌ No Reliable ✅ Yes ❌ No Ordering ✅ Maintained ❌ Not Guaranteed ACK ✅ Yes ❌ No Retransmission ✅ Yes ❌ No Speed Slower Faster Best For Files, Banking, HTTP Streaming, Gaming, Video Calls

HTTP vs WebSocket

HTTP WebSocket Request → Response Full Duplex Client starts communication Both client and server can send anytime Short-lived connection Persistent connection Not real-time Real-time Uses TCP Uses TCP

WebSocket vs WebRTC

WebSocket WebRTC Client-Server Peer-to-Peer Uses TCP Primarily Uses UDP Chat Applications Video Calls Notifications Voice Calls Multiplayer Synchronization Screen Sharing

Which Protocol Should You Use?

Situation Protocol Website HTTP File Transfer FTP Send Email SMTP Read Email IMAP Live Chat WebSocket Video Call WebRTC Banking TCP File Download TCP Live Streaming UDP Online Gaming UDP

Interview Questions

Why does FTP use two connections?

One connection is used for commands (Control Connection) and another is used for transferring files (Data Connection).

Why is UDP used in Video Calls?

Because speed is more important than reliability. Missing a few packets is better than introducing delay.

Why is TCP used in Banking?

Every packet must reach the destination correctly and in the correct order.

Is WebSocket Peer-to-Peer?

No.

WebSocket is a Client-Server protocol that supports Full Duplex communication.

Which protocol sends emails?

SMTP

Which protocol reads emails?

IMAP

Quick Revision

Topic Remember HTTP Request-Response FTP Two Connections SMTP Send Email IMAP Read Email WebSocket Full Duplex Client-Server WebRTC Peer-to-Peer TCP Reliable, Ordered UDP Fast, Best Effort Live Streaming UDP Banking TCP Video Calls WebRTC + UDP

Summary

  • HTTP → Websites and APIs
  • FTP → File Transfer
  • SMTP → Sending Emails
  • IMAP → Reading Emails
  • WebSocket → Real-time Client-Server Communication
  • WebRTC → Peer-to-Peer Video/Audio Communication
  • TCP → Reliable and Ordered
  • UDP → Fast and Connectionless

원문에서 계속 ↗

추출 본문 · 출처: dev.to · https://dev.to/shifa_2/hld1computer-networks-notes-3bf1

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다