A robust, multi-threaded TCP-based chat and file-sharing system implemented in C, supporting concurrent clients, room-based messaging, private messaging, and file transfers with comprehensive logging.
- Multi-threaded Architecture: Supports 15+ concurrent clients
- Room-based Messaging: Create and join chat rooms dynamically
- Private Messaging: Whisper functionality for direct communication
- File Transfer System: Queue-based file sharing with validation
- Thread Safety: Mutex and semaphore-based synchronization
- Comprehensive Logging: Timestamped server activity logs
- Graceful Shutdown: Clean resource management on SIGINT
- Cross-platform: Debian 12 and macOS compatible
# Clean and compile
make clean
make all
# This creates:
# - chatserver (server executable)
# - chatclient (client executable)./chatserver <port>
# Example: ./chatserver 8080./chatclient <server_ip> <port>
# Example: ./chatclient 127.0.0.1 8080/join <room_name>- Join or create a room/leave- Leave current room/broadcast <message>- Send message to room/whisper <username> <message>- Send private message/sendfile <filepath> <username>- Send file to user/help- Show available commands/exit- Disconnect from server
./quick_test.shTests basic functionality: compilation, server startup, client connection, logging, and shutdown.
./test_suite.shTests all features mentioned in the project report:
- Concurrent user load (15+ clients)
- Username validation
- Room management
- Message broadcasting
- Private messaging
- File transfer and validation
- Error handling
- Client exit and server shutdown
./enhanced_test_suite.shTests ALL 10 required scenarios from assignment specifications:
- ✅ Concurrent User Load (30+ clients) - Tests server limits
- ✅ Duplicate Usernames - Username collision handling
- ✅ File Upload Queue Limit - 10 users, 5 queue limit
- ✅ Unexpected Disconnection - Client crash simulation
- ✅ Room Switching - Automatic room transitions
- ✅ Oversized File Rejection - >3MB file handling
- ✅ SIGINT Server Shutdown - Graceful Ctrl+C shutdown
- ✅ Rejoining Rooms - Leave/rejoin functionality
- ✅ Same Filename Collision - Conflict resolution
- ✅ File Queue Wait Duration - Queue timing tracking
- Test logs:
test_results/directory (generated by the scripts) - Server logs:
server_log.txt - Test report:
test_results/test_report.txtorenhanced_test_report.txt - Test comparison: See
TEST_COMPARISON.mdfor detailed coverage analysis
├── Makefile # Build configuration
├── common.h # Shared definitions
├── common_utils.c # Shared utility functions
├── server/
│ ├── server.c # Main server implementation
│ ├── utils.c # Server logging functions
│ └── file_handler.c # File transfer queue management
├── client/
│ ├── client.c # Main client implementation
│ └── utils.c # Client utility functions
├── test_suite.sh # Comprehensive test automation
├── quick_test.sh # Quick functionality test
├── TESTING_GUIDE.md # Detailed testing instructions
├── PROJECT_REPORT.md # Complete project documentation
└── README.md # This file
- Message Types: JOIN, LEAVE, BROADCAST, WHISPER, SENDFILE, EXIT
- Username: Alphanumeric, max 16 characters
- Room Names: Alphanumeric, max 32 characters
- File Types: .txt, .pdf, .jpg, .png (max 3MB)
- Server: Main thread + client handler threads + file worker threads
- Client: Main thread + receive thread
- Synchronization: Mutexes for data protection, semaphores for queue control
- Queue System: Max 5 concurrent uploads
- Worker Threads: 5 dedicated file processing threads
- Storage:
uploads/directory with automatic naming conflict resolution
- Concurrent Clients: 15+ simultaneous connections
- Message Throughput: ~1000 messages/second
- File Transfer: Queue-limited to 5 concurrent uploads
- Memory: Stable usage, no memory leaks
- Startup Time: < 2 seconds
- Shutdown Time: < 3 seconds
-
Port already in use:
pkill -f chatserver
-
Permission denied:
chmod +x chatserver chatclient chmod +x quick_test.sh test_suite.sh
-
Compilation errors:
make clean make all
-
Client connection issues:
- Check server is running:
ps aux | grep chatserver - Verify port:
lsof -i :8080(macOS) ornetstat -ln | grep 8080(Linux)
- Check server is running:
The automated test suite covers:
- ✅ Compilation: Zero warnings with
-Wall -Wextra - ✅ Concurrency: 15+ simultaneous clients
- ✅ Messaging: Broadcast and whisper functionality
- ✅ File Transfer: Upload queue and validation
- ✅ Error Handling: All error conditions
- ✅ Logging: Comprehensive activity tracking
- ✅ Shutdown: Graceful resource cleanup
Implemented requirements:
- ✅ Multi-threaded TCP server
- ✅ 15+ concurrent client support
- ✅ Room-based group messaging
- ✅ Private messaging (whisper)
- ✅ File transfer with queue (max 5)
- ✅ Username validation (alphanumeric, max 16)
- ✅ File restrictions (.txt, .pdf, .jpg, .png, max 3MB)
- ✅ Thread-safe operations
- ✅ Comprehensive logging
- ✅ Graceful shutdown (SIGINT)
- ✅ Exact executable names:
chatserverandchatclient
- TESTING_GUIDE.md: Comprehensive testing instructions
- PROJECT_REPORT.md: Detailed technical report
- Server logs: Real-time activity in
server_log.txt
- C Compiler: GCC with C99 support
- POSIX Threads: pthread library
- POSIX Semaphores: Named semaphores for cross-platform compatibility
- Standard Libraries: socket, signal, file I/O
- Code Standards: C99 compliant, no warnings
- Memory Management: No memory leaks detected
- Thread Safety: Proper synchronization primitives
- Error Handling: Comprehensive error checking
- Cross-platform: Tested on Debian 12 and macOS
- Documentation: Complete with examples and test cases
Author: Multi-threaded Systems Programming Project
Compatibility: Debian 12, macOS
License: Educational Use
Last Updated: May 2025