IT432 – Network Programming | Assiut University
A multi-threaded TCP client-server system that compresses files over the network using GZip.
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.
- ✅ 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.gznext to the original - ✅ Activity log on both server and client windows
- ✅ Clean WinForms GUI — drag-and-drop designer compatible
NetworkCompressionSystem/
├── CompressionServer/
│ └── CompressionServer/
│ └── Form1.cs ← Server logic (all code here)
├── CompressionClient/
│ └── CompressionClient/
│ └── Form1.cs ← Client logic (all code here)
└── README.md
- Windows OS
- Visual Studio 2019 or later
- .NET Framework 4.7.2+ or .NET 6+
Open two separate Visual Studio instances:
- Open
CompressionServer/CompressionServer.sln - Open
CompressionClient/CompressionClient.sln
Or open both
.csprojfiles inside one solution.
Each project needs its form controls added via the WinForms Designer.
See the Designer Reference section below for the exact control names.
- Start the server first → click Start Server
- Start the client → enter the server IP → click Connect
- Browse for any file → click Send File
- The compressed
.gzfile is saved automatically next to the original
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
| 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
| 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
To test the multi-threading capability with 3 simultaneous clients:
- Build the client project
- Navigate to the output folder:
CompressionClient\bin\Debug\net6.0-windows\ - Double-click
CompressionClient.exethree times → three separate windows open - Connect all three → send different files at the same time
- Watch the server log show all three sessions running concurrently and the counter show Clients Connected: 3
| 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 |
- 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
[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
This project is for educational purposes as part of the IT432 course at Assiut University.