Transport Layer Protocols and Socket Programming Study Guide
Assignment 2 Briefing and Requirements
Timeline and Grading
- The assignment is due by the end of the week, Sunday, May 17.
- The assignment is worth a total of marks.
- Marks are divided equally: for the code and for the demonstration.
- Demonstrations will begin after May 17, and students will have a two-week window to attend any lab session to demonstrate their code.
Project Scope: Tuple Space System
- Players must use C to design a network system using the TCP protocol.
- The system consists of a server and multiple clients interacting with a shared "tuple space" used for storing data.
- Template Files Provided:
tuple_space_server: Acts as the main server; manages the shared tuple space and shared statistics. It handles process requests arriving on the server side.space_worker: Called by thespace_serverto manage thread handling. This involves managing separate sockets for each client.space_client: Supports the system itself.
Learning Goals
- Understanding how TCP sockets communicate and establish connections.
- Learning the mechanics of forwarding requests to a server and receiving responses.
- Mastering concurrency and shared memory management.
Implementation Stages
- Stage 1: Handling a single thread (one client at a time).
- Stage 2: Handling concurrent clients and managing a shared tuple space among them.
Technical Requirements
- TCP Requirements: The server creates a TCP listener and waits for connections. Clients also create sockets to communicate.
- Compilation: The transcript mentions a
monopackage to compile C# code (noted despite the project being in C); students pass prompts to run the basic structure. - Shared Memory Safety: Because memory is shared among threads, students must implement safety logs (mutexes/locks).
- Messaging Format: Requests include
read,get, andput. Data is structured as tuples with a key and a value.
Execution Environment
- Linux: Can execute scripts directly.
- Windows: Use a PowerShell script. Students can copy the provided code into a
.ps1file and execute it in PowerShell.
Testing
- Testing must cover both Stage 1 and Stage 2.
- Implement tests for invalid inputs using the provided sample file.
- Use the provided script to execute concurrent clients for stress testing.
Transport Layer Services and Socket Programming
Transport Layer Overview
- The transport layer is the second layer in the OSI model (relative to session/application context mentioned).
- It provides logical communication between application processes running on different hosts.
- Sockets serve as the interface for applications to access transport layer services.
TCP vs. UDP Protocols
- TCP (Transmission Control Protocol):
- Characteristics: Reliable, in-order delivery, byte stream-oriented, connection-based.
- Connection: Requires a three-way handshake before data transfer.
- Sockets: The server utilizes one "Welcome Socket" to listen for connections and creates a unique socket for every client connected. If clients connect, the server has sockets ().
- Data: Addresses are extraction once during the initial connection.
- UDP (User Datagram Protocol):
- Characteristics: Unreliable, any-order delivery, packet/datagram-oriented, connectionless.
- Sockets: Only one datagram socket is needed on the server side to communicate with any number of clients.
- Data: Since there is no connection state, the server requires the IP and Port information from every packet to respond correctly.
Multiplexing and Demultiplexing
- Multiplexing: The process at the sender of gathering data from multiple sockets, enveloping data with header information to create segments.
- Demultiplexing: The process at the receiver of delivering received segments to the correct socket.
- UDP Demultiplexing: Identified by a 2-tuple: (Destination IP, Destination Port).
- TCP Demultiplexing: Identified by a 4-tuple: (Source IP, Source Port, Destination IP, Destination Port). This allows a server to support multiple simultaneous TCP sockets for the same port (e.g., Port ) because each connection has a unique source IP/port combination.
Principles of Reliable Data Transfer (RDT)
The Challenge
- Applications want a reliable channel where packets are never lost, corrupted, or reordered.
- The lower layer (Network Layer/IP) is unreliable. RDT protocols must bridge this gap.
Reliability Mechanisms
- Checksums: Used to detect bit-level data corruption.
- Acknowledgments (ACK): Receiver tells sender that the packet was received correctly.
- Negative Acknowledgments (NAK): Receiver tells sender that a packet had errors.
- Timeouts: Sender waits a specific duration; if no ACK is received, it assumes the packet was lost and retransmits.
- Sequence Numbers: Added to packets so the receiver can detect and discard duplicates resulting from premature timeouts or retransmissions.
Stop-and-Wait and Sliding Window Protocols
Stop-and-Wait Protocol
- Operational Logic: Sender sends one packet and stops to wait for an ACK before sending the next.
- Scenarios:
- Packet Loss: If a packet is lost, the sender times out and retransmits.
- ACK Loss: If the ACK is lost, the sender retransmits. The receiver detects a duplicate via sequence numbers (e.g., alternating and ) and resends the ACK.
- Delayed ACK: If an ACK arrives after a timeout, the late ACK is handled, and the receiver ignores the duplicate packet but sends a confirmation ACK again.
- Performance Issues: Inefficient due to high idle time during the Round Trip Time (RTT). The sender utilization is low.
Sliding Window (Pipelined) Protocols
- Allows the sender to have multiple "in-flight" packets that have not yet been acknowledged.
- Go-Back-N (GBN):
- Uses a cumulative acknowledgment. If the receiver sends ACK , it means all packets up to were received.
- Sender has a single timer for the oldest unacknowledged packet.
- If a timeout occurs, the sender retransmits all packets in the window (starting from the missing one).
- Receiver discards out-of-order packets and sends an ACK for the last correctly received in-order packet.
- Selective Repeat (SR):
- Individual acknowledgments: Receiver sends an ACK for specifically received packets, even if out-of-order.
- Sender maintains a separate timer for every unacknowledged packet.
- Only the specific lost/timed-out packet is retransmitted.
- Receiver buffers out-of-order packets until missing ones arrive to provide an in-order sequence to the application.
Connectionless Transport: UDP Protocol Details
Characteristics of UDP
- It is "No Frills" and bare-bones.
- No connection establishment (reducing RTT delay).
- No congestion control; it transmits as fast as the application allows.
- Used by: DNS (Port ), Streaming media (loss-tolerant but rate-sensitive), Online Games, and HTTP/3.
UDP Header Structure
- The header is exactly bytes ( bits).
- Header Fields:
- Source Port: bits.
- Destination Port: bits.
- Length: bits (Total length including header).
- Checksum: bits (Used for error detection).
Questions & Discussion
Q: Why use UDP if TCP is objectively better?
- A: UDP is chosen for speed. Connection establishment in TCP adds delay. Many applications (like games or DNS) prioritize speed and can handle reliability at the application layer if needed.
Q: How does a server handle multiple clients in code?
- A: By using a loop to continuously accept connections and creating a new socket for each client session.
Q: Regarding Assignment 2: Do we need to implement checksums or RDT protocols?
- A: No. Assignment 2 focuses on thread safety (locking the shared tuple space) and basic TCP communication. Advanced reliability tasks are part of Assignment 3.