🔥 Carbon Web Server

High-Performance HTTP/HTTPS Server with WebSocket Support

✓ It works!

The Carbon web server is installed and running successfully. This is the default page that is displayed when the server is working correctly.

About This Server

Carbon is a high-performance, production-ready HTTP/HTTPS server written in C for Linux systems. It features modern web technologies including WebSocket support, SSL/TLS encryption, and comprehensive security measures.

⚡ High Performance

Epoll-based async I/O, zero-copy file transfers, and thread pooling

🔒 Secure by Default

SSL/TLS support, rate limiting, security headers, and input sanitization

🌐 WebSocket Ready

Full RFC 6455 compliant WebSocket implementation for real-time apps

🛠️ Easy Configuration

Simple Linux-style configuration file with comments

Quick Links

Test WebSocket Documentation

Configuration

The server is configured through the server.conf file located in the server root directory.

Basic Configuration Example

# Carbon Web Server Configuration File

# Server listening port
port = 8080

# Enable HTTPS (requires valid certificates in certs/ directory)
use_https = false

# Log file location
log_file = log/server.log

# Maximum number of worker threads
max_threads = 4

# Server name or IP address
server_name = localhost

# Enable verbose logging
verbose = true

# Enable WebSocket support
enable_websocket = true
Note: After modifying the configuration file, restart the server for changes to take effect.

Enabling HTTPS

To enable HTTPS support, you'll need SSL certificates. You can use self-signed certificates for testing or obtain certificates from Let's Encrypt for production.

Generate Self-Signed Certificates (Testing Only)

# Create certificates directory
mkdir -p certs

# Generate self-signed certificate
openssl req -x509 -newkey rsa:4096 -nodes \
    -keyout certs/key.pem \
    -out certs/cert.pem \
    -days 365 \
    -subj "/C=US/ST=State/L=City/O=Organization/CN=localhost"

Enable HTTPS in Configuration

# Edit server.conf
use_https = true
Warning: Self-signed certificates will show security warnings in browsers. For production, use certificates from a trusted Certificate Authority like Let's Encrypt.

WebSocket Support

Carbon includes full WebSocket support (RFC 6455 compliant) for building real-time applications.

Test WebSocket Connection

Use the built-in test client:

# Browser
http://localhost:8080/websocket-test.html

# Command line (requires wscat: npm install -g wscat)
wscat -c ws://localhost:8080

# Secure WebSocket (if HTTPS enabled)
wscat -c wss://localhost:443

JavaScript Example

// Connect to WebSocket server
const ws = new WebSocket('ws://localhost:8080');

// Connection opened
ws.addEventListener('open', (event) => {
    console.log('Connected!');
    ws.send('Hello Server!');
});

// Listen for messages
ws.addEventListener('message', (event) => {
    console.log('Received:', event.data);
});

Directory Structure

Understanding the server directory layout:

Common Tasks

Start the Server

./server

Stop the Server

# Press Ctrl+C in the server terminal
# Or send SIGTERM signal
kill -TERM $(pgrep -f './server')

View Logs

tail -f log/server.log

Test HTTP Connection

curl http://localhost:8080

Rebuild After Code Changes

make clean && make

Troubleshooting

Port Already in Use

If you see "Address already in use" errors:

# Find process using port 8080
sudo lsof -i :8080

# Or
sudo netstat -tulpn | grep 8080

# Kill the process
kill -9 <PID>

Permission Denied for Port 443

Ports below 1024 require root privileges:

# Option 1: Run as root (not recommended for production)
sudo ./server

# Option 2: Use setcap to grant capability
sudo setcap 'cap_net_bind_service=+ep' ./server
./server

WebSocket Connection Failed

Security Best Practices