How sua0649/os-project2025 works
Project type and purpose
• This is a C-based, multi-threaded client-server chat application (“NERV Terminal”) that allows multiple clients to connect to a centralized server, exchange broadcast and private messages, and optionally render a terminal or GTK GUI.
• The README confirms use of POSIX sockets, Pthreads for concurrency, mutexes/condition variables for synchronization, and an optional NCurses/GTK UI.
File structure
• Top-level:
• client.c / client.h: core client logic (connect, send/receive broadcast/private)
• client_p2p.c / client_p2p.h: peer-to-peer client variant
• server.c / server.h: central server, connection acceptor, thread‐pool manager
• Utils/cJSON.c & .h: JSON encode/decode utility used by both client and server
• makefile: build recipes for client, client_p2p, server
• Executables (client.exe, client_p2p.exe, server.exe)
• Patterns:
• Client‐Server separation
• Thread‐pool on the server (producer–consumer queue with condition variables)
• Shared JSON library for message serialization
Incorporate README architecture hints
a. Main components:
• Client Application (client & client_p2p modules)
• Server Application (listener, dispatcher, thread-pool)
• Shared Utils Library (cJSON)
• Underlying OS Services (POSIX Sockets, Pthread)
• Optional UI Layer (NCurses/GTK)
• Data Store (in-memory message queue guarded by mutex/condvar)
b. Relationships & interactions:
• Clients ⇄ Server via TCP sockets
• Server listener enqueues incoming messages into a synchronized queue
• Thread‐pool workers dequeue messages, parse JSON, route to all or target client socket(s)
• JSON library invoked at both ends for serialization/deserialization
• UI Layer hooks into client send/receive routines
c. Architectural patterns & design principles:
• Client–Server architecture
• Thread‐pool (fixed worker threads) implementing producer–consumer pattern
• Modular separation: networking, business logic, UI, utilities
• Use of mutexes and condition variables for safe queue access
d. Key technologies/frameworks:
• C language
• POSIX Socket API
• Pthread Library (pthread_mutex_t, pthread_cond_t)
• cJSON (third-party JSON parser)
• Optional UI: NCurses or GTK