Skip to content

odeliyach/Network-Infrastructure-C

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Printable Characters Counter (PCC)

🚀 Read This First

  • The authoritative project compass is docs/instructions_network.txt. All development choices, error semantics, and protocol details align with that document.

🧠 Architecture Overview

  • Role: Implements a TCP printable-characters counter with deterministic client/server protocol flow.
  • Server (pcc_server): Accepts TCP sessions, counts printable bytes (ASCII 32–126) from each byte stream, persists aggregated frequency metrics, and emits statistics on atomic SIGINT handling.
  • Client (pcc_client): Streams a file over TCP using the mandated protocol, prints the printable-count returned by the server, and exits with zero on success.
  • Concurrency Model: Iterative single-threaded loop with signal-aware acceptance; SIGINT processing is atomic relative to in-flight client handling as required by the assignment text.

🧠 Protocol Diagram

sequenceDiagram
    participant Client
    participant Server
    Client->>Server: N (uint32, network byte order)
    Server-->>Client: Length accepted
    Client->>Server: N bytes payload
    Server->>Server: Count printable bytes
    Server-->>Client: C (uint32, network byte order)
Loading

🧠 Core Networking Concepts

  • TCP Handshake: The server binds to INADDR_ANY, listens with backlog 10, and completes the three-way handshake before payload exchange. This guarantees reliable, ordered byte streams prior to protocol framing.
  • Network Byte Order (Endianness): Length and count fields are serialized with htonl/ntohl to enforce big-endian wire representation across heterogeneous hosts.
  • PCC Algorithm: Byte streams are ingested in bounded buffers (1 KiB) to avoid oversized allocations. Each byte is classified as printable or non-printable; printable bytes increment both per-connection and global frequency vectors. Only successful sessions contribute to pcc_total, ensuring TCP errors or premature disconnects do not contaminate statistics.
  • Robust Error Handling: All critical system calls (socket, bind, listen, accept, read, write, connect) are validated. TCP-specific disconnect conditions (ETIMEDOUT, ECONNRESET, EPIPE) log and continue without mutating global counters; other failures are fatal with descriptive diagnostics.

🛠️ Build, Test, and Run

  • Toolchain: gcc, make (flags: -Wall -Werror -O3 -std=c11 -D_POSIX_C_SOURCE=200809).
  • Build artifacts: bin/pcc_server, bin/pcc_client.
  • Commands:
    • make all — compile server and client.
    • make test — loopback integration smoke test using a temporary file and SIGINT-driven shutdown.
    • make clean — remove build outputs.
  • Manual execution examples:
    • ./bin/pcc_server 5555
    • ./bin/pcc_client 127.0.0.1 5555 ./path/to/file

🐳 Dockerized Execution

  1. Build: docker build -t pcc .
  2. Run server: docker run --rm -p 5555:5555 pcc ./bin/pcc_server 5555
  3. Run client (loopback to host or container IP): docker run --rm --network host -v $(pwd):/data pcc ./bin/pcc_client 127.0.0.1 5555 /data/yourfile

🔄 CI/CD

  • GitHub Actions workflow ci.yml performs make all and make test on every push and pull request to enforce compilation hygiene and protocol smoke coverage.

🧭 Repository Layout

  • src/ - C sources (pcc_server.c, pcc_client.c).
  • docs/ - assignment and protocol instructions (instructions_network.txt).
  • bin/ - build outputs (generated).

Academic Integrity Notice

This repository is for portfolio and educational purposes only. If you are a student currently taking an Operating Systems course, copying this code violates academic integrity policies. I do not take responsibility for disciplinary actions against individuals who misuse this code.

📄 License

This project is licensed under the MIT License - see LICENSE file for details.


Built by Odeliya Charitonova · GitHub · LinkedIn

Computer Science student @ Tel Aviv University, School of CS & AI

About

TCP printable-characters counter: single-threaded server/client that streams files, counts ASCII printable bytes (ASCII 32–126) with robust error handling, and reports per-session/global statistics. Includes Makefile, integration tests, and Docker support.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors