Skip to content

KhaledHima/NetworkCompressionSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🗜️ Network File Compression System

IT432 – Network Programming | Assiut University
A multi-threaded TCP client-server system that compresses files over the network using GZip.


📌 Overview

This project is a two-application system built in C# Windows Forms (.NET):

Application Role
CompressionServer Listens for clients, receives files, compresses them with GZip, sends them back
CompressionClient Connects to the server, sends a file, receives the compressed result, saves it automatically

The server handles multiple clients simultaneously — each client connection runs on its own thread, so many clients can compress files at the same time without blocking each other.


✨ Features

  • ✅ Multi-threaded server — handles unlimited simultaneous clients
  • ✅ Real-time client counter on the server GUI ("Clients Connected: N")
  • ✅ Persistent TCP session — Connect once, send many files
  • ✅ Heartbeat system — client detects if server goes down and shows a warning
  • ✅ Session ID system — stopping and restarting the server kills ghost threads immediately
  • ✅ GZip compression in-memory using System.IO.Compression.GZipStream
  • ✅ Auto-save — compressed file saved as originalname.ext.gz next to the original
  • ✅ Activity log on both server and client windows
  • ✅ Clean WinForms GUI — drag-and-drop designer compatible

🏗️ Project Structure

NetworkCompressionSystem/
├── CompressionServer/
│   └── CompressionServer/
│       └── Form1.cs          ← Server logic (all code here)
├── CompressionClient/
│   └── CompressionClient/
│       └── Form1.cs          ← Client logic (all code here)
└── README.md

🚀 How to Run

Prerequisites

  • Windows OS
  • Visual Studio 2019 or later
  • .NET Framework 4.7.2+ or .NET 6+

Step 1 — Open the Projects

Open two separate Visual Studio instances:

  1. Open CompressionServer/CompressionServer.sln
  2. Open CompressionClient/CompressionClient.sln

Or open both .csproj files inside one solution.

Step 2 — Build the GUI (Designer)

Each project needs its form controls added via the WinForms Designer.
See the Designer Reference section below for the exact control names.

Step 3 — Run

  1. Start the server first → click Start Server
  2. Start the client → enter the server IP → click Connect
  3. Browse for any file → click Send File
  4. The compressed .gz file is saved automatically next to the original

🔌 Communication Protocol

CLIENT  ──── "CONNECT" (10 bytes) ────────────────►  SERVER
CLIENT  ◄─── "OK"      (2 bytes)  ────────────────   SERVER

CLIENT  ──── "PING"    (4 bytes)  ────────────────►  SERVER   (every 3 sec)
CLIENT  ◄─── "PONG"    (4 bytes)  ────────────────   SERVER

CLIENT  ──── "SEND"    (4 bytes)  ────────────────►  SERVER
CLIENT  ──── fileSize  (4 bytes)  ────────────────►  SERVER
CLIENT  ──── fileData  (N bytes)  ────────────────►  SERVER
CLIENT  ◄─── compSize  (4 bytes)  ────────────────   SERVER
CLIENT  ◄─── compData  (M bytes)  ────────────────   SERVER

🧰 Designer Reference

Server — CompressionServer/Form1.cs

Control Type Name Default Text
Server status Label lblStatus "Stopped"
Client counter Label lblClients "Clients Connected: 0"
Port input TextBox txtPort "9050"
Start button Button btnStart "Start Server"
Stop button Button btnStop "Stop Server"
Activity log ListBox lstLog (empty)

Event wiring: btnStart → btnStart_Click · btnStop → btnStop_Click


Client — CompressionClient/Form1.cs

Control Type Name Default Text
Server IP TextBox txtServerIP "127.0.0.1"
Port TextBox txtPort "9050"
Connect Button btnConnect "Connect"
Disconnect Button btnDisconnect "Disconnect"
File path TextBox txtFilePath (ReadOnly)
Browse Button btnBrowse "Browse File"
Send Button btnSend "Send File"
Status Label lblStatus "Not connected."
Original size Label lblOriginal "Original size: —"
Compressed size Label lblCompressed "Compressed size: —"
Activity log ListBox lstLog (empty)

Event wiring: btnConnect → btnConnect_Click · btnDisconnect → btnDisconnect_Click · btnBrowse → btnBrowse_Click · btnSend → btnSend_Click


🧪 Testing Multiple Clients

To test the multi-threading capability with 3 simultaneous clients:

  1. Build the client project
  2. Navigate to the output folder:
    CompressionClient\bin\Debug\net6.0-windows\
    
  3. Double-click CompressionClient.exe three times → three separate windows open
  4. Connect all three → send different files at the same time
  5. Watch the server log show all three sessions running concurrently and the counter show Clients Connected: 3

📚 Concepts Used

Concept Where Used
TcpListener / TcpClient Server accept loop & client connect
NetworkStream All data transfer
Thread (one per client) Server concurrency
GZipStream In-memory file compression
Thread.IsBackground = true Auto-cleanup on app exit
Control.Invoke() Cross-thread UI updates in WinForms
Session ID pattern Killing ghost threads on server restart
Heartbeat (PING/PONG) Detecting server disconnection on client side

📖 References

  • Book: Hands-On Network Programming with C# and .NET Core (2019)
  • Book: TCP/IP Sockets in C# – Practical Guide for Programmers
  • Book: C# Network Programming – Richard Blum
  • Course: IT432 – Network Programming, Assiut University

👨‍💻 Author

[Khaled Ibrahim]
IT432 – Network Programming
Faculty of Computers and Information, Assiut University

Supervised by:
Dr. Ali Hussein Ahmed
IT432 – Network Programming
Faculty of Computers and Information, Assiut University

📄 License

This project is for educational purposes as part of the IT432 course at Assiut University.

About

Multi-threaded TCP file compression system — server compresses files sent by multiple simultaneous clients using GZip.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages