Networks 4

foNetworks 4

Socket

  • = an endpoint of communication between 2 devices on a network
  • Is an interface between application layer and transport layer
  • Located between operating system (e.g. Windows, Linux) and application programs
  • To access the services provided by the TCP/IP protocol suite, an application needs to use the instructions defined in the socket interface
  • Type of socket
  • Stream Socket (TCP): connection oriented, reliable, ordered, error-checked delivery
  • Datagram Socket (UDP): fast, unreliable, connectionless communication
  • Socket address consists of a combination of IP address and port no.
  • Basic communication flow of socket
  • https://www.keil.com/pack/doc/mw6/network/html/using_network_sockets_bsd.html
  • Bind is to bind to the port no.

Client-Server architecture

  • = a network design model in which multiple client devices communicate with and request services from a central server
  • Note: in socket programming, run server first before running client
  • Server
  • = a computer or program that provides services or resources to clients over a network
  • A server program is an infinite program: when it starts, it runs infinitely unless a problem arises or shuts down
  • Waits for incoming requests from clients
  • When a request arrives, it responds to the request
  • E.g. web server, file server, database server, email server
  • Client
  • = a computer or program that initiates a request for services or resources from a server over a network
  • A client program is finite: it is started by the user (or another application program) and terminates when the service is complete
  • Opens the communication channel using the IP address of the remote host & the well-known port address of the specific server program running on that machine
  • IP address leads you to the network interface
  • Port number indicates which program to send the data to
  • Can have multiple servers running on the same server, but diff. ports
  • After a channel of communication is opened, the client sends its request and receives a response
  • Although the request-response part may be repeated several times, the whole process is finite → eventually comes to an end
  • E.g. web browser, email program
  • Advantages
  • Centralized resourced management
  • Server holds and manages resources (files, databases, applications, etc)
  • Allows for central control of data, security policies, backups, and user access
  • Scalability
  • New clients can be added easily without changing the system
  • Server can be upgraded (add more resources: RAM or using load balancing) to serve more clients
  • Improved security
  • Enforce security policies from the server side
  • E.g. user authentication, file permissions, monitoring network traffic
  • Ease of maintenance
  • Software updates, backups, and system configuration are done on the server
  • Reduces the need to configure every client device
  • Reliability and consistency
  • Data stored on the server is kept consistent
  • All clients access from 1 source which should be most up-to-date
  • Remote access support
  • Clients can access servers from anywhere over the internet, enabling remote work, cloud services, and web applications
  • If 1 client is down, the server and other clients are not affected
  • Disadvantages
  • Single point of failure
  • If server is down, all clients lose access to service (whole network down)
  • High cost of setup and maintenance
  • Servers are expensive and require skilled administrators
  • Initiating infrastructure and licensing costs can be high
  • Network congestion and overload
  • Possibility of network congestion, server overload, slow down network
  • Complexity
  • Configuration and management of a secure and efficient server environment can be complex
  • Network dependence
  • Clients rely heavily on a stable network connection required

Peer-to-peer (P2P) architecture

  • = a decentralized network model where each computer (peer) acts both as a client and server
  • No central server ⇒ each peer can request and provide services or resources directly to other peers
  • Key features
  • All peers have equal role
  • They can initiate (send a request) or response to a request
  • Decentralized
  • No central point of control
  • Resources are distributed among peers
  • Resource sharing
  • Resources or services are shared among peers
  • Autonomy
  • Each peer manages its own resources and may be online or offline at any time
  • E.g. BitTorrent peer-to-peer file sharing, blockchain networks
  • Advantages
  • Low cost
  • No need for expensive server hardware or infrastructure
  • Scalability
  • New peers can join the network easily to contribute resources
  • System can grow without major reconfiguration
  • No single point of failure
  • 1 peer fails does not affect the whole network ⇒ limited impact to network
  • Resource sharing
  • Peers can share files, processing power, or bandwidth directly with others
  • Disadvantages
  • Lack of centralized control
  • No central authority to manage users, resources, and security
  • Harder to enforce rules and monitor activity
  • Security risks
  • Each peer is responsible for its own security
  • Malicious peers can spread malware or unauthorized content
  • Data consistency issues
  • Files in peers not guaranteed to be up-to-date
  • Synchronization is difficult
  • Performance
  • Performance suffers if there are few online peers or peers have low bandwidth

[Application layer] Protocols

Dynamic Host Configuration Protocol (DHCP)

  • Automatically assign IP addresses and other network configuration parameters to devices (clients) on a network
  • IP address
  • Subnet masks
  • Default gateways
  • DNS server addresses
  • Lease duration
  • Without DHCP, every device would need to be manually configured
  • Error-prone
  • Inefficient
  • Unscalable
  • How it works (DORA)
  • Discover: client sends a broadcast to find available DHCP servers
  • Offer: DHCP server replies with an offer including an IP address and configuration
  • Request: client requests to use the offered IP address
  • Acknowledge: server confirms and leases the IP address to the client
  • DHCP server sends the address to the client for acknowledgement
  • Uses UDP for sending a broadcast to find available DHCP servers
  • Client device does not have an IP address ⇒ cannot use TCP as connection needs to be established
  • Light-weight, minimal overhead
  • Connectionless ⇒ no handshakes, no session setup
  • Types of IP address allocation:
Static IP addressManual configuration: device manually configured with its IP address, subnet mask, gateway, DNS
DHCP server is not involved ⇒ no DHCP request is sent
DHCP reservation: using MAC address of the specific device
Always get the same IP address from the DHCP pool ⇒ a DHCP request is required to obtain the IP address
Dynamic IP addressDHCP server leases a dynamic IP address (reusable) to the client for a period of time

Domain Name System (DNS)

  • Translates domain names (e.g. www.google.com; human-readable format) into IP address (used for routing; machine-readable format)
  • User uses a file transfer client to access file transfer server at a remote host
  • Only the server name (e.g. www.google.com) is known, but TCP/IP suite needs IP address of the server to make a connection
  • Steps to map host name to IP address:
  1. User passes host name to file transfer client (FTC)
  2. FTC passes host name to DNS client
  3. DNS client sends a message to DNS server with a query containing the FT server name, using IP address of DNS server (pic on right)
  4. DNS server responds with IP address of FT server
  5. DNS client passes IP address to FT client
  6. FT client uses IP address to access FT server
  • Hierarchy
  • Name-address resolution steps:
  1. Check local cache (on host / DNS client)
  • Client (resolver) checks its own cache
  • If IP address is found locally, client uses IP address to route the message in the network ⇒ no need step 2
  1. Query Local DNS server (ISP’s DNS resolver)
  • ISP = Internet Service Provider
  • If not found locally, client sends query to the DNS server specified in the IP configuration
  • Server checks its own cache
  1. Query the Global DNS hierarchy (if not cached)
  • If ISP DNS resolver does not have the answer, it must contact the DNS hierarchy of distributed database
  • 2 resolution methods (based on client resolver)
  • Recursive resolution: ISP DNS resolver will resolve the name
  • Root DNS server: direct to the Top-Level Domain (TLD) server (e.g. .com, .edu, .org, .sg)
  • TLD server: direct to the Authoritative DNS Server for the domain
  • Authoritative DNS Server: returns actual IP address
  • Iterative resolution: client-resolver / local ISP DNS resolver performs queries step by step, using referrals from each server
  • Root DNS server: returns address of a TLD server
  • TLD server: returns address of authoritative DNS server
  • Authoritative DNS Server: returns actual IP address
  1. Return IP address to client
  • DNS resolver sends the resolved IP address back to client
  • Client uses IP address to route the message in the network
  • Advantages of DNS using UDP
  • Speed
  • Fast as users expect pages to load fast
  • UDP does not need to establish a connection setup
  • Small size
  • DNS queries and responses easily fit in 1 UDP datagram
  • Low overhead
  • Simple header
  • Requires less processing time and bandwidth
  • Stateless
  • Simple request and response
  • Does not need to maintain connection

Hypertext Transfer Protocol (HTTP)

  • Note: using HTTP != HTML (i.e. it must not be for a webpage
  • Allows clients (e.g. browsers) to fetch hypertext documents, images, scripts, etc from web server
  • Uses ports 80, 443 (HTTPS)
  • Uses client-server model
  • Client sends a HTTP request
  • Server responds with a HTTP response
  • ⇒ these 2 separate requests are treated independently
  • A stateless protocol ⇒ server does not keep information about client
  • Each request-response pair is independent
  • Client initializes the transaction by sending a request
  • Server replies by sending a response
  • HTTP transaction between client and server
  • HTTP request includes:
  • Request line: GET /test.html HTTP/1.1
  • xGET: HTTP command/method that the client wants to perform
  • test.html: path of the relevant document
  • HTTP/1.1: version of the HTTP used by the client
  • Header fields: provides additional info to web server
  • E.g. Host: example.com
  • Message body (optional): for POST requests, message body contains the data submitted
  • HTTP response includes:
  • Status line: summarises whether server is able to perform request from client
  • E.g. HTTP/1.1 200 OK
  • HTTP/1.1: HTTP version used by server
  • Status code: reason phrase
  • 200: OK; 404: Not found; 500: Internal Server Error
  • Header fields: provides additional info
  • E.g. Content-Type: text/plain
  • Message body: contains document in format specified by Content-Type header field

Simple Mail Transfer Protocol (SMTP)

  • Protocol used to send/relay email across the internet, not for rerieving email
  • Uses Port 25/587 (secure)
  • Uses client-server model
  • SMTP Message Structure:
  • Envelope (Control Information)
  • MAIL FROM: sender address
  • RCPT TO: recipient address
  • DATA: begin message content
  • Message Headers: describes sender, receiver, content type, etc
  • Message Body: content of email

Post Office Protocol v3 (POP3)

  • Protocol to download emails from server to client and delete the message from the mailbox on the server
  • Uses port 110/995 (secure)
  • Uses client-server model: email client and server
Mail access starts with the client
Client opens a connection to the server on TCP port 110
It then sends its user name and password to access the mailbox
The user can then list and retrieve the mail messages, 1 by 1

Internet Message Access Protocol v4

  • Similar to POP3 and allows user to view and manage messages on server
  • Allows user to access mail messages from multiple locations (email clients) and ensure that all copies are synchronized and consistent
  • Extended functionality:
  • Obtain info about the message or examine header fields without retrieving the entire message
  • Search and retrieve portions of a message (partial retrieval)
  • Useful for slow-speed connections
  • Uses Port 143/993 (secure)
  • Microsoft Outlook, Apple Mail, Mozilla Thunderbird, Webmail email client uses IMAPv4

File Transfer Protocol (FTP)

  • Protocol for copying a file from one host to another
  • Resolves some problems with 2 hosts having:
  • Diff. file name conventions
  • Diff. ways of representing text and data
  • Diff. directory structures
  • Differs from other client-server applications as it establishes 2 connections between the hosts
  • Control Connection / information (port 21)
  • Used for commands from clients and response from server
  • Remains open during the session
  • Data Connection / transfer (port 20)
  • Used for file transfer: upload, download, and directory listing
  • Open when needed, and closed after data transfer