A simple Inter-Process Communication (IPC) based project demonstrating:
- File → Client → Server → Client round-trip
- Multi-threaded request handling
- Chunk-based network transmission
- Server-side string manipulation (convert to UPPERCASE)
- Overview
- Features
- Repository Structure
- High-Level Architecture
- How It Works
- Key Concepts (Detailed)
- Build & Run
- Example
- Notes
- Author
- Multi-threaded TCP server
- Client sends file in chunks
- Server converts received text to UPPERCASE
- Client writes processed output into a new file
- Proper socket cleanup + error handling
- Beginner-friendly and interview-friendly design
IPC-Client-Server/
├── Makefile # Outer makefile (builds both client & server)
├── readme.txt
│
├── as_4_1_server/
│ ├── build/Makefile
│ ├── include/as_4_1_server.h
│ ├── src/as_4_1_server.c
│ ├── doc
│
└── as_4_1_client/
├── build/Makefile
├── include/as_4_1_client.h
├── src/as_4_1_client.c
├── test.txt
├── doc
+-------------------+ +----------------+ +----------------+
| Client | ---> | Connect Socket | ---> | Send Chunk |
| (read input file) | | | | |
+-------------------+ +----------------+ +----------------+
| |
| v
| +---------------------------+
| | Server (accept client) |
| +---------------------------+
| |
| v
| +---------------------------+
| | Thread (client_request) |
| +---------------------------+
| |
| v
| +---------------------------+
| | Read & Modify |
| | (convert to UPPERCASE) |
| +---------------------------+
| |
| v
+--------------------+ <--------+ +---------------------------+
| Client | | | Send Back (response) |
| (write output) | <--------+--------------+---------------------------+
+--------------------+
- Reads input text file.
- Splits into chunks.
- Connects to the server using TCP.
- Sends each chunk.
- Receives modified (UPPERCASE) data.
- Writes to output file.
- Binds + listens on a TCP port.
- Accepts new client connections.
- Spawns a thread per client.
- Thread receives data, modifies it (toupper).
- Sends modified data back.
- TCP is connection-oriented → ensures reliable delivery, correct ordering, retransmission, congestion control.
- Suitable for file transfer because:
- No packet loss
- Guaranteed byte order
- Stream-based → large data transfer possible
socket(), bind(), listen(), accept()
connect(), send(), recv()Each client is handled by a dedicated POSIX thread:
+------------------+
| Main Server |
| (accept loop) |
+---------+--------+
|
v
+-----------------------+
| pthread for Client #1 |
+-----------------------+
|
v
File Data
This prevents blocking:
- One slow client does NOT affect others.
- Server scales to many clients.
Why chunking?
- TCP is a streaming protocol;
send()may not send all bytes at once. - Chunking avoids memory spikes.
- Each chunk is predictable in size (e.g., 1024 bytes).
Workflow:
Client → Request filename
Server → Send file size
Client → Start receiving chunks
Server → send(chunk)
Client → write(chunk)
The system checks:
- File existence
- Read/Write permission
- Partial sends
- Broken connections
- Invalid input
- Network errors
| Feature | TCP | UDP |
|---|---|---|
| Reliability | ✔ | ✖ |
| Ordered packets | ✔ | ✖ |
| Automatic retransmission | ✔ | ✖ |
| File transfer friendly | ✔ | ✖ |
| Low latency | ✖ | ✔ |
Since this system focuses on accurate file delivery, TCP is the correct choice.
makeor
make -C as_4_1_server/build/./as_4_1_server/bin/as_4_1_servermakeor
make -C as_4_1_client/build/./as_4_1_client/bin/as_4_1_client <ip>
<path of the file>./as_4_1_server/bin/as_4_1_server
./as_4_1_client/bin/as_4_1_client 127.0.0.1
as_4_1_client/test.txt
test.txt
werfsdgfverrrrrrrrrrrrrrrrrrrrrrrrrrrrr
output.txt
WERFSDGFVERRRRRRRRRRRRRRRRRRRRRRRRRRRRR
- Works on Linux and WSL environments.
- Chunk size can be adjusted as needed.
- Thread pool can be added for optimization.
Manvendra Pratap Singh