# anandk28/2a_stop_and_wait_protocol architecture

> Architecture diagram of the GitHub repository anandk28/2a_stop_and_wait_protocol, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anandk28/2a_stop_and_wait_protocol
- Repository: https://github.com/anandk28/2a_stop_and_wait_protocol

## Overview

##### Project type and purpose
- This is a network protocol demo tool written in Python.
- It consists of two processes: one binds & listens (named “client” in the code) and one connects (named “server” in the code), exchanging data frames with acknowledgements.

##### Main components
a. Client process
- Python script that binds to localhost:8000, listens for incoming connections, reads user input frames, sends them, and waits for ACKs.
b. Server process
- Python script that connects to localhost:8000, receives frames, prints them, and replies with an acknowledgement message.
c. Network channel
- The underlying TCP socket on localhost (port 8000) conveying frames and ACKs.

##### Relationships and interactions
- Client → Network: “Frame” messages (user-entered data)
- Server ← Network: receives frames
- Server → Network: “Acknowledgement Received” messages
- Client ← Network: receives ACKs, then prompts for next frame
- Strict stop-and-wait pattern: client sends one frame, waits for its ACK before sending the next.

##### Architectural patterns & design principles
- Single-threaded, sequential I/O on each side
- Simple request–response loop (no parallelism or pipelining)
- Clear separation of concerns:
- Input handling (user frame creation)
- Network I/O (socket send/receive)
- Acknowledgement logic (stop and wait)

##### Elements
- Clear labels for each of the two Python scripts (names and roles).
- The TCP connection as an explicit link or channel between them.
- Annotations of the port number and socket operations.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User actor
    User["User (frame input)"]:::user
    %% Client process
    subgraph "Client Process"
        Client["Client Script\nbind & listen on localhost:8000\nwhile True:\n  • input() → send(frame)\n  • recv(ACK)"]:::client
    end
    %% Server process
    subgraph "Server Process"
        Server["Server Script\nconnect to localhost:8000\nwhile True:\n  • recv(frame) → print\n  • send(ACK)"]:::server
    end
    %% Data flows
    User -->|"input frame"| Client
    Client -->|"Frame (data payload)\nsend() on port 8000"| Server
    Server -->|"ACK\nsend() on port 8000"| Client

    %% Link styles
    linkStyle 1 stroke:#f00,stroke-dasharray:5 5;
    linkStyle 2 stroke:#f00,stroke-dasharray:5 5;

    %% Styles
    classDef user fill:#FFE4B5,stroke:#333,stroke-width:1px;
    classDef client fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef server fill:#90EE90,stroke:#333,stroke-width:1px;
```
