Skip to content

Educational demo of inter-process communication using TCP sockets. Features a server that accepts client connections, spawns threads to process incoming text, converts data to uppercase using a synchronized shared buffer, and returns the result to the client.

Notifications You must be signed in to change notification settings

Manvendra199922/IPC-Client-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

IPC Client–Server (Uppercase Text Processor)

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)

Index


🚀 Features

  • 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

📦 Repository Structure

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


🖥️ High-Level Architecture

Flow Diagram (ASCII)

+-------------------+      +----------------+      +----------------+
| 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)     | <--------+--------------+---------------------------+
+--------------------+

⚙️ How It Works

Client

  1. Reads input text file.
  2. Splits into chunks.
  3. Connects to the server using TCP.
  4. Sends each chunk.
  5. Receives modified (UPPERCASE) data.
  6. Writes to output file.

Server

  1. Binds + listens on a TCP port.
  2. Accepts new client connections.
  3. Spawns a thread per client.
  4. Thread receives data, modifies it (toupper).
  5. Sends modified data back.

📌 Key Concepts (Detailed)

1. TCP Networking

  • 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

Main TCP APIs Used

socket(), bind(), listen(), accept()
connect(), send(), recv()

2. Multi-Threaded Server Architecture

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.

3. Chunk-Based File Transmission

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)

4. Error Handling Strategy

The system checks:

  • File existence
  • Read/Write permission
  • Partial sends
  • Broken connections
  • Invalid input
  • Network errors

5. Why TCP instead of UDP?

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.


🛠️ Build & Run

1. Build the Server

make

or

make -C as_4_1_server/build/

Run:

./as_4_1_server/bin/as_4_1_server

2. Build the Client

make

or

make -C as_4_1_client/build/

Run:

./as_4_1_client/bin/as_4_1_client <ip>
<path of the file>

🧪 Example

./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

📝 Notes

  • Works on Linux and WSL environments.
  • Chunk size can be adjusted as needed.
  • Thread pool can be added for optimization.

👤 Author

Manvendra Pratap Singh

About

Educational demo of inter-process communication using TCP sockets. Features a server that accepts client connections, spawns threads to process incoming text, converts data to uppercase using a synchronized shared buffer, and returns the result to the client.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published