Contents
  1. The Seven Layers
  2. Protocol Reference
  3. Socket Programming Concepts
  4. Client-Server Architecture
← All posts

The OSI Model and Application-Layer Protocols

The OSI model divides network communication into seven layers. Each layer has a defined responsibility and a set of protocols. This post maps the key protocols to their layers and default ports.

The Seven Layers

The OSI (Open Systems Interconnection) model is a conceptual framework that standardises network communication into seven layers. Each layer provides services to the layer above and uses services from the layer below.

LayerNamePrimary function
7ApplicationEnd-user protocols (HTTP, SMTP, DNS)
6PresentationEncoding, encryption, compression
5SessionSession management, synchronisation
4TransportEnd-to-end delivery, flow control (TCP, UDP)
3NetworkLogical addressing, routing (IP)
2Data LinkHop-to-hop delivery, MAC addressing
1PhysicalBit transmission over physical medium

In practice, TCP/IP collapses layers 5, 6, 7 into a single Application layer, and layers 1, 2 into a Network Access layer.

Protocol Reference

Key protocols by layer and default port:

ProtocolLayerPortPurpose
HTTP780Web traffic
HTTPS7443Encrypted web traffic
SMTP725Email sending
IMAP7143Email retrieval (keeps on server)
POP37110Email retrieval (downloads)
DNS753Domain name resolution
FTP721File transfer
SSH722Secure remote shell
RDP73389Remote desktop
LDAP7389Directory services
SNMP7161Network device management
XMPP75222Messaging
MQTT71883IoT messaging (pub/sub)
CoAP75683Constrained IoT devices
SMB7445File sharing (Windows)
NFS72049Network file system (Unix)
TCP4N/AReliable stream transport
UDP4N/AUnreliable datagram transport

Socket Programming Concepts

Sockets are the API through which applications access the transport layer. A socket represents one endpoint of a two-way communication link.

Two types:

  • Stream socket (TCP): reliable, ordered, connection-oriented byte stream.
  • Datagram socket (UDP): unreliable, unordered, connectionless packets.

The socket lifecycle:

  1. Creation: socket() creates a socket of the specified type.
  2. Binding and addressing: bind() associates the socket with a local address and port.
  3. Listening and accepting (server): listen() and accept() wait for incoming connections.
  4. Connecting (client): connect() initiates a connection to a remote address.
  5. Transmission: send() / recv() or write() / read().
  6. Closing: close() releases the socket.

Sockets can be blocking (calls wait until data is available) or non-blocking (calls return immediately, requiring polling or event-driven handling). Socket options allow configuration of behaviour such as socket reuse (SO_REUSEADDR) and timeouts.

Client-Server Architecture

The client-server model separates two roles:

  • Server: listens for incoming connections, processes requests, sends responses. Examples: web server (Apache, Nginx, IIS), database server, file server.
  • Client: initiates connections, sends requests, receives responses. Examples: browsers, mobile apps, CLI tools.

Key concerns in a client-server system: protocol choice (HTTP vs gRPC vs WebSocket), security (TLS, authentication), performance (load balancing, caching), and deployment (GCP, AWS, bare metal).

← All posts