Skip to content

ManveerAnand/multiserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ’ฌ MultiServer - Real-Time Chat & Web Server

A high-performance C-based server that combines HTTP web serving and real-time chat in a single application. Built with advanced networking concepts including event-driven architecture, connection pooling, and intelligent protocol detection.

๐Ÿš€ Quick Start

Just want to try it? Run this:

./run.sh

Want to see the chat demo? Run this:

./demo.sh

That's it! ๐ŸŽ‰

โœจ What Can It Do?

๐ŸŒ Web Server (HTTP)

  • Static file serving - Host websites, images, CSS, JavaScript
  • Smart routing - Automatic index.html serving
  • File browsing - Directory listings when enabled
  • Multi-format support - HTML, CSS, JS, images, text files

๐Ÿ’ฌ Real-Time Chat Server (Fully Working!)

  • Persistent chat sessions - Stay connected, no reconnection needed
  • Multiple chat rooms - Create and join different rooms
  • User management - Nicknames, user lists, join/leave notifications
  • Rich commands - All commands working: /help, /join, /nick, /list, /quit and more
  • Live messaging - Real-time chat with other users via telnet
  • Command processing - Fixed newline handling for all terminal clients

โšก Advanced Features

  • Dual-protocol - HTTP (port 8080) + Chat (port 8081) simultaneously
  • Event-driven - Handles 1000+ concurrent connections efficiently
  • Smart detection - Automatically routes HTTP vs Chat traffic
  • Configurable - Easy INI-style configuration
  • Production logging - Multi-level logs with colors

๐ŸŽฎ Try It Out

Option 1: Web Server

./run.sh
# Then visit: http://localhost:8080

Option 2: Chat Server (Working!)

./run.sh
# In another terminal, connect via telnet:
telnet localhost 8081
# Then try these commands:
/help
/join lobby
/nick YourName
Hello everyone!
/quit

Option 3: Multi-User Chat Demo

# Terminal 1 - Start the server:
./run.sh

# Terminal 2 - First user:
telnet localhost 8081
/join lobby
/nick Alice
Hello everyone!

# Terminal 3 - Second user:  
telnet localhost 8081
/join lobby
/nick Bob
Hi Alice!
# Now they can chat in real-time!

Note: All chat commands are now working properly via telnet! The /help command will show you all available options.

๐Ÿ’ป Chat Commands (All Working!)

Connect via telnet localhost 8081 and use these commands:

Command Description Example
/help โœ… Show all commands /help
/join <room> โœ… Join or create a room /join lobby
/nick <name> โœ… Change your nickname /nick Alice
/list users โœ… See who's in your room /list users
/list rooms โœ… See available rooms /list rooms
/leave โœ… Leave current room /leave
/clear โœ… Clear the screen /clear
/quit โœ… Exit chat /quit
<message> โœ… Send chat message Hello world!

All commands are working properly! Connect with multiple telnet sessions to test real-time chat.

๐Ÿ› ๏ธ Installation

Prerequisites

  • Linux/WSL (Ubuntu, Debian, etc.)
  • GCC compiler (sudo apt install build-essential)
  • Make (usually included with build-essential)

Build & Run

# Clone or download the project
cd multiserver

# Build (first time only)
make

# Run the server
./run.sh

# Stop the server (if needed)
./stop.sh

# Or run manually
./multiserver -c config/test.conf

Troubleshooting

  • Port already in use? - The run script automatically stops existing servers
  • Permission denied? - Make scripts executable: chmod +x *.sh
  • Build errors? - Install build tools: sudo apt install build-essential

๐Ÿ“ Project Structure

multiserver/
โ”œโ”€โ”€ run.sh              # Quick start script  
โ”œโ”€โ”€ demo.sh             # Interactive chat demo
โ”œโ”€โ”€ stop.sh             # Stop server script
โ”œโ”€โ”€ multiserver         # Main executable (after build)
โ”œโ”€โ”€ Makefile           # Build configuration
โ”œโ”€โ”€ config/            # Server configuration
โ”‚   โ””โ”€โ”€ test.conf      # Default config file
โ”œโ”€โ”€ src/               # Source code
โ”‚   โ”œโ”€โ”€ main.c         # Program entry point
โ”‚   โ”œโ”€โ”€ server.c       # Core server engine
โ”‚   โ”œโ”€โ”€ connection.c   # Connection management
โ”‚   โ”œโ”€โ”€ enhanced_chat.c # Chat system
โ”‚   โ””โ”€โ”€ logging.c      # Logging system
โ”œโ”€โ”€ include/           # Header files
โ”œโ”€โ”€ www/               # Web content directory
โ”‚   โ””โ”€โ”€ index.html     # Default web page
โ””โ”€โ”€ tools/             # Demo and testing tools

โš™๏ธ Configuration

Edit config/test.conf to customize:

[server]
http_port = 8080        # Web server port
chat_port = 8081        # Chat server port  
max_connections = 1000  # Concurrent connection limit

[logging]
level = INFO           # DEBUG, INFO, WARN, ERROR
console = true         # Show logs in terminal
to_file = true         # Save logs to file

[chat]
max_rooms = 100        # Maximum chat rooms
max_users_per_room = 50 # Users per room limit

๐Ÿ”ง Architecture Highlights

  • Event-Driven: Uses select() for non-blocking I/O
  • Protocol Detection: Automatically distinguishes HTTP vs Chat traffic
  • Connection Pooling: Efficient memory and resource management
  • Persistent Sessions: Chat connections stay alive for real-time messaging
  • Modular Design: Clean separation between HTTP, Chat, and Core systems

๐ŸŽฏ Technical Features

Performance

  • 1000+ concurrent connections supported
  • Non-blocking I/O for maximum efficiency
  • Memory-safe connection management
  • Signal handling for graceful shutdown

Networking

  • Dual-port operation (HTTP + Chat simultaneously)
  • Protocol multiplexing on single server
  • Keep-alive connections for chat persistence
  • Automatic cleanup of idle connections

Development

  • Clean C code with comprehensive error handling
  • Configurable logging with multiple levels
  • Easy build system with Make
  • Cross-platform (Linux/Unix/WSL)

๐Ÿš€ What's Next?

This server demonstrates core networking concepts and is ready for extension:

  • Authentication system - User login/registration
  • File upload handling - POST request processing
  • Database integration - Persistent chat history
  • WebSocket support - Browser-based chat client
  • Load balancing - Multiple server instances
  • SSL/TLS encryption - Secure connections

๐Ÿ“Š Current Status

โœ… Fully Functional - Both HTTP and Chat working perfectly
โœ… All Commands Working - /help, /join, /quit, etc. all functional via telnet
โœ… Production Ready - Handles multiple users simultaneously
โœ… Fixed Command Processing - Proper newline handling for all terminal clients
โœ… Real-Time Chat - Multiple users can chat simultaneously
โœ… Well Documented - Clear code and extensive comments
โœ… Easy to Use - Simple scripts for immediate testing
โœ… Extensible - Clean architecture for future features

Ready to showcase networking skills with working chat demo! ๐ŸŽ‰

About

๐Ÿš€ High-performance C-based server combining real-time chat and HTTP web serving with advanced networking concepts including event-driven architecture, connection pooling, and intelligent protocol detection.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors