Skip to content

utkarshhxd/Unified-Communication-Protocol-main

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

UCP β€” Unified Communication Protocol

UCP Logo Go Version License Platform

A unified, real-time communication protocol for chat messaging and file transfer over TCP

Features β€’ Quick Start β€’ Documentation β€’ Contributing β€’ License


πŸ“‹ Table of Contents


🎯 Overview

UCP (Unified Communication Protocol) is a lightweight, high-performance application-layer protocol built in Go that enables real-time chat messaging and file transfer over a single TCP connection. Designed with simplicity and efficiency in mind, UCP provides a unified communication solution for local networks, development environments, and small-scale deployments.

Key Highlights

  • πŸš€ Unified Protocol: Single TCP connection for both chat and file transfer
  • 🌐 Network-Ready: Deploy on local networks with automatic IP detection
  • πŸ“¦ Chunked Transfers: Efficient large file handling with 64KB chunks
  • πŸ”„ Resume Support: Automatic recovery from connection interruptions
  • πŸ“Š Activity Tracking: Comprehensive logging and monitoring
  • πŸ—οΈ Modular Design: Clean architecture with separation of concerns
  • ⚑ High Performance: Built with Go for optimal concurrency and speed

Use Cases

  • Local Network Communication: Team collaboration on private networks
  • Development Environments: Quick file sharing and messaging during development
  • Educational Projects: Learning network protocols and Go concurrency
  • Small-Scale Deployments: Lightweight communication solution for small teams

✨ Features

Core Features

  • βœ… Real-Time Chat Messaging: Instant message broadcasting to all connected clients
  • βœ… File Transfer: Send files of any size with automatic chunking
  • βœ… Multi-Client Support: Server handles unlimited concurrent connections
  • βœ… Connection Recovery: Resume interrupted file transfers automatically
  • βœ… Activity Logging: Comprehensive JSON-based activity tracking
  • βœ… Network Deployment: Automatic IP detection and network interface binding
  • βœ… Keep-Alive: PING/PONG mechanism for connection health monitoring
  • βœ… Graceful Shutdown: Clean server shutdown with signal handling

Advanced Features

  • πŸ”’ Thread-Safe Operations: All operations protected with mutex locks
  • πŸ“ Structured Logging: JSON-formatted logs for easy parsing
  • 🌍 Cross-Platform: Works on Linux, macOS, and Windows
  • 🎯 Zero Dependencies: Pure Go implementation, no external dependencies
  • πŸ”§ Configurable: Command-line arguments for port and host configuration
  • πŸ“Š Client Tracking: Track connected clients with IP addresses and timestamps

πŸ—οΈ Architecture

System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        UCP Server                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ Protocol β”‚  β”‚Transport β”‚  β”‚ Handlers β”‚  β”‚ Tracking β”‚ β”‚
β”‚  β”‚  Layer   β”‚β†’ β”‚  Layer   β”‚β†’ β”‚  Layer   β”‚β†’ β”‚  Layer   β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚       ↓              ↓              ↓              ↓        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚         TCP Listener (0.0.0.0:8080)              β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         ↑                    ↑                    ↑
         β”‚                    β”‚                    β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚Client 1β”‚          β”‚Client 2β”‚          β”‚Client Nβ”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Component Breakdown

1. Protocol Layer (protocol/)

  • Message type definitions (JOIN, LEAVE, MSG, FILE, etc.)
  • Message serialization/deserialization
  • File chunking logic (64KB chunks)
  • Protocol validation

2. Transport Layer (transport/)

  • TCP connection management
  • Message I/O operations
  • Binary data handling for file transfers
  • Connection state management

3. Handlers Layer (handlers/)

  • Server-side message processing
  • Client registration and management
  • Message broadcasting
  • File transfer coordination

4. Recovery Layer (recovery/)

  • Chunk tracking and validation
  • Resume logic for interrupted transfers
  • File completion detection

5. Tracking Layer (tracking/)

  • Activity logging
  • JSON-formatted log entries
  • Activity querying and filtering

Data Flow

Client β†’ TCP Connection β†’ Transport Layer β†’ Protocol Parser
                                                      ↓
Server ← TCP Connection ← Transport Layer ← Message Handler
                                                      ↓
                                              Activity Tracker

Message Flow Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Client1 β”‚                    β”‚ Server  β”‚                    β”‚ Client2 β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
     β”‚                               β”‚                               β”‚
     β”‚ 1. JOIN Alice                 β”‚                               β”‚
     β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€>β”‚                               β”‚
     β”‚                               β”‚                               β”‚
     β”‚                               β”‚ 2. ACK                        β”‚
     β”‚<───────────────────────────────                               β”‚
     β”‚                               β”‚                               β”‚
     β”‚                               β”‚ 3. Broadcast JOIN             β”‚
     β”‚                               β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€>β”‚
     β”‚                               β”‚                               β”‚
     β”‚ 4. MSG Hello                  β”‚                               β”‚
     β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€>β”‚                               β”‚
     β”‚                               β”‚                               β”‚
     β”‚                               β”‚ 5. Broadcast MSG              β”‚
     β”‚                               β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€>β”‚
     β”‚                               β”‚                               β”‚
     β”‚ 6. FILE image.png (chunk 1/3) β”‚                               β”‚
     β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€>β”‚                               β”‚
     β”‚                               β”‚                               β”‚
     β”‚                               β”‚ 7. Broadcast FILE            β”‚
     β”‚                               β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€>β”‚
     β”‚                               β”‚                               β”‚

πŸ“¦ Prerequisites

Required

  • Go 1.25.1 or higher - Download Go
  • Git - For cloning the repository
  • Network Access - For network deployment

Optional

  • Docker - For containerized deployment
  • Make - For using Makefile commands (optional)
  • Wireshark - For network packet inspection (debugging)

System Requirements

  • CPU: Any modern processor (x86_64, ARM64)
  • RAM: Minimum 128MB, recommended 512MB+
  • Storage: 50MB for binaries, additional space for logs
  • Network: TCP/IP support, port 8080 (or custom) available

πŸš€ Installation

Linux

Using Go Install

# Clone the repository
git clone https://github.com/yourusername/ucp.git
cd ucp

# Build the project
go build -o ucp-server ./server
go build -o ucp-client ./client

# Or use the build script
chmod +x build.sh
./build.sh

Using Package Manager (if available)

# Example for Debian/Ubuntu (if package created)
sudo apt-get install ucp-server ucp-client

macOS

# Clone the repository
git clone https://github.com/yourusername/ucp.git
cd ucp

# Build using Homebrew (if formula created)
brew install ucp

# Or build from source
go build -o ucp-server ./server
go build -o ucp-client ./client

Windows

Using Go Install

# Clone the repository
git clone https://github.com/yourusername/ucp.git
cd ucp

# Build the project
go build -o ucp-server.exe ./server
go build -o ucp-client.exe ./client

# Or use the build script
.\build.bat

Using Chocolatey (if package created)

choco install ucp

Docker

Build Docker Image

# Build server image
docker build -t ucp-server:latest -f Dockerfile.server .

# Build client image
docker build -t ucp-client:latest -f Dockerfile.client .

Run with Docker Compose

# Start server
docker-compose up -d server

# Start client
docker-compose run --rm client 192.168.1.100 8080

Dockerfile.server:

FROM golang:1.25-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o ucp-server ./server

FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/ucp-server .
EXPOSE 8080
CMD ["./ucp-server"]

Dockerfile.client:

FROM golang:1.25-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o ucp-client ./client

FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/ucp-client .
CMD ["./ucp-client"]

⚑ Quick Start

1. Start the Server

# Navigate to server directory
cd server

# Start server on default port (8080)
go run main.go

# Or use compiled binary
./ucp-server

# Custom port
go run main.go 9090

Expected Output:

========================================
UCP Server started successfully!
Port: 8080
Network Access: Enabled (listening on all interfaces)
========================================
Server IP Addresses:
  - localhost:8080
  - 127.0.0.1:8080
  - 192.168.1.100:8080
========================================
Clients can connect using any of the above IPs
Waiting for connections...
========================================

2. Connect a Client

# Navigate to client directory
cd client

# Connect to localhost
go run main.go

# Connect to network server
go run main.go 192.168.1.100 8080

# Or use compiled binary
./ucp-client 192.168.1.100 8080

3. Start Chatting

> Enter your username: Alice
> Hello everyone!
> [Bob]: Hi Alice!
> /file document.pdf
> Sent file document.pdf successfully

βš™οΈ Configuration

Environment Variables

Create a .env file in the project root:

# Server Configuration
UCP_SERVER_PORT=8080
UCP_SERVER_HOST=0.0.0.0
UCP_SERVER_MAX_CLIENTS=1000
UCP_SERVER_CHUNK_SIZE=65536

# Logging Configuration
UCP_LOG_LEVEL=info
UCP_LOG_FILE=logs/activity.log
UCP_LOG_MAX_SIZE=100MB
UCP_LOG_MAX_AGE=7

# Network Configuration
UCP_NETWORK_TIMEOUT=30s
UCP_KEEP_ALIVE_INTERVAL=60s

# Client Configuration
UCP_CLIENT_DOWNLOAD_DIR=downloads
UCP_CLIENT_TIMEOUT=30s

Example .env file:

UCP_SERVER_PORT=8080
UCP_SERVER_HOST=0.0.0.0
UCP_LOG_LEVEL=info
UCP_LOG_FILE=logs/activity.log
UCP_CLIENT_DOWNLOAD_DIR=downloads

Server Configuration

Parameter Default Description
PORT 8080 Server listening port
HOST 0.0.0.0 Network interface to bind to
CHUNK_SIZE 65536 File chunk size in bytes (64KB)
MAX_CLIENTS 1000 Maximum concurrent clients
LOG_FILE logs/activity.log Activity log file path
LOG_LEVEL info Logging level (debug, info, warn, error)

Client Configuration

Parameter Default Description
SERVER_HOST localhost Server hostname or IP
SERVER_PORT 8080 Server port
DOWNLOAD_DIR downloads/ Directory for received files
TIMEOUT 30s Connection timeout

πŸ“– Usage

Server Commands

# Start server on default port
ucp-server

# Start server on custom port
ucp-server 9090

# With environment variables
UCP_SERVER_PORT=9090 ucp-server

Client Commands

# Connect to localhost:8080
ucp-client

# Connect to specific server
ucp-client 192.168.1.100 8080

# Connect with custom port
ucp-client localhost 9090

Client Interactive Commands

Once connected, use these commands:

Command Description Example
/help Show help message /help
/file <path> Send a file /file document.pdf
/quit or /exit Quit the client /quit
/status Show client status /status
/ping Ping the server /ping
/files Show active file transfers /files
<message> Send chat message Hello everyone!

Network Deployment

Step 1: Start Server on Laptop 1

cd server
go run main.go

Note the IP address displayed (e.g., 192.168.1.100).

Step 2: Connect from Laptop 2

Option A: Using Compiled Binary

  1. Copy ucp-client.exe (or ucp-client on Linux/Mac) to Laptop 2
  2. Run:
    ./ucp-client 192.168.1.100 8080

Option B: Build on Laptop 2

  1. Copy entire project to Laptop 2
  2. Build client:
    cd client
    go build -o ucp-client main.go
  3. Run:
    ./ucp-client 192.168.1.100 8080

Step 3: Firewall Configuration

Windows:

# Allow inbound connections on port 8080
New-NetFirewallRule -DisplayName "UCP Server" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow

Linux:

# Using ufw
sudo ufw allow 8080/tcp

# Using iptables
sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT

macOS:

# Allow incoming connections
sudo pfctl -f /etc/pf.conf

πŸ“‘ Protocol Specification

Message Types

Type Format Description
JOIN JOIN <username> Client joins the server
LEAVE LEAVE <username> Client leaves the server
MSG MSG <username_len> <username> <msg_len> <message> Chat message
FILE FILE <username_len> <username> <filename_len> <filename> <filesize> <chunk_num> <total_chunks>\n<4-byte length><data> File transfer chunk
ACK ACK <message_id> Acknowledgment
RESUME RESUME <username> <filename> <last_chunk_id> Resume file transfer
PING PING Keep-alive ping
PONG PONG Keep-alive response

Message Format

Text Messages

All text messages follow the format:

<COMMAND> [parameters]\n

Binary Data

File chunks are sent as:

FILE <username_length> <username> <filename_length> <filename> <filesize> <chunk_num> <total_chunks>\n
<4-byte length><binary data>

Where <4-byte length> is a big-endian 32-bit integer indicating the data size.

File Transfer

Files are automatically split into 64KB chunks for efficient transfer:

  • Chunk Size: 65536 bytes (64KB)
  • Last Chunk: May be smaller than 64KB
  • Chunk Numbering: Starts at 0
  • Metadata: Each chunk includes filename, size, and position

Recovery Mechanism

When a connection drops during file transfer:

  1. Client tracks received chunks
  2. On reconnect, client sends RESUME message
  3. Server identifies missing chunks
  4. Server resends missing chunks
  5. Client completes file assembly

πŸ”Œ API Documentation

Protocol Endpoints

JOIN

Request:

JOIN Alice

Response:

ACK 1234567890

Broadcast:

JOIN Alice

LEAVE

Request:

LEAVE Alice

Broadcast:

LEAVE Alice

MSG (Chat Message)

Request:

MSG 5 Alice 13 Hello everyone!

Broadcast:

MSG 5 Alice 13 Hello everyone!

Parameters:

  • username_length: Length of username (5 for "Alice")
  • username: Sender's username
  • message_length: Length of message (13 for "Hello everyone!")
  • message: Message content

FILE (File Transfer)

Request:

FILE 5 Alice 8 image.png 192000 0 3
<65536 bytes of binary data>

Parameters:

  • username_length: Length of username
  • username: Sender's username
  • filename_length: Length of filename
  • filename: File name
  • filesize: Total file size in bytes
  • chunk_num: Current chunk number (0-indexed)
  • total_chunks: Total number of chunks
  • <data>: Binary file data (preceded by 4-byte length)

RESUME

Request:

RESUME Alice image.png 45

Response:

ACK 1234567891

Parameters:

  • username: Username requesting resume
  • filename: File to resume
  • last_chunk_id: Last successfully received chunk ID

Error Codes

Code Description Solution
CONNECTION_REFUSED Server not running or port blocked Start server, check firewall
USERNAME_TAKEN Username already in use Choose different username
INVALID_MESSAGE Malformed message format Check message syntax
FILE_NOT_FOUND File doesn't exist Verify file path
CHUNK_ERROR Chunk validation failed Retry transfer

πŸ› οΈ Development

Project Structure

ucp/
β”œβ”€β”€ client/              # Client executable
β”‚   └── main.go         # Client main entry point
β”œβ”€β”€ server/             # Server executable
β”‚   └── main.go        # Server main entry point
β”œβ”€β”€ protocol/           # Protocol definitions
β”‚   └── protocol.go    # Message types, parsing, serialization
β”œβ”€β”€ transport/          # Transport layer
β”‚   └── connection.go  # TCP connection handling
β”œβ”€β”€ handlers/           # Server handlers
β”‚   └── handlers.go    # Message handlers, client management
β”œβ”€β”€ recovery/           # Recovery system
β”‚   └── tracker.go     # Chunk tracking, resume logic
β”œβ”€β”€ tracking/           # Activity tracking
β”‚   └── activity.go    # Logging and activity tracking
β”œβ”€β”€ logs/              # Log files (generated)
β”‚   └── activity.log  # Activity log file
β”œβ”€β”€ build.bat          # Windows build script
β”œβ”€β”€ build.sh           # Linux/Mac build script
β”œβ”€β”€ go.mod             # Go module file
β”œβ”€β”€ .gitignore         # Git ignore rules
└── README.md          # This file

Building from Source

# Clone repository
git clone https://github.com/yourusername/ucp.git
cd ucp

# Download dependencies
go mod download

# Build server
go build -o ucp-server ./server

# Build client
go build -o ucp-client ./client

# Build both (Linux/Mac)
./build.sh

# Build both (Windows)
.\build.bat

Running Tests

# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run tests with verbose output
go test -v ./...

# Run specific package tests
go test ./protocol
go test ./transport
go test ./handlers

Code Coverage

# Generate coverage report
go test -coverprofile=coverage.out ./...

# View coverage report
go tool cover -html=coverage.out

# Coverage threshold (example)
go test -cover -coverprofile=coverage.out ./...
go tool cover -func=coverage.out | grep total | awk '{if ($3+0 < 80) exit 1}'

Linting & Formatting

# Format code
go fmt ./...

# Run golint (if installed)
golint ./...

# Run go vet
go vet ./...

# Run staticcheck (if installed)
staticcheck ./...

# Run all checks
go fmt ./... && go vet ./... && go test ./...

Development Setup

  1. Fork the repository

  2. Clone your fork:

    git clone https://github.com/yourusername/ucp.git
    cd ucp
  3. Create a branch:

    git checkout -b feature/your-feature-name
  4. Make changes and test:

    go test ./...
    go build ./...
  5. Commit changes:

    git add .
    git commit -m "feat: add your feature"
  6. Push and create PR:

    git push origin feature/your-feature-name

🚒 Deployment

Production Deployment

Systemd Service (Linux)

Create /etc/systemd/system/ucp-server.service:

[Unit]
Description=UCP Server
After=network.target

[Service]
Type=simple
User=ucp
WorkingDirectory=/opt/ucp
ExecStart=/opt/ucp/ucp-server 8080
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

Enable and start:

sudo systemctl enable ucp-server
sudo systemctl start ucp-server
sudo systemctl status ucp-server

Windows Service

Use NSSM (Non-Sucking Service Manager):

# Install service
nssm install UCP-Server "C:\ucp\ucp-server.exe" "8080"
nssm start UCP-Server

Docker Deployment

Docker Compose

Create docker-compose.yml:

version: "3.8"

services:
  ucp-server:
    build:
      context: .
      dockerfile: Dockerfile.server
    ports:
      - "8080:8080"
    volumes:
      - ./logs:/app/logs
    environment:
      - UCP_SERVER_PORT=8080
      - UCP_LOG_FILE=logs/activity.log
    restart: unless-stopped
    networks:
      - ucp-network

networks:
  ucp-network:
    driver: bridge

Deploy:

docker-compose up -d
docker-compose logs -f ucp-server

Rollback Procedures

Quick Rollback

# Stop current version
systemctl stop ucp-server

# Restore previous binary
cp ucp-server.backup ucp-server

# Start previous version
systemctl start ucp-server

Docker Rollback

# Rollback to previous image
docker-compose pull
docker-compose up -d --force-recreate

πŸ”’ Security

Security Practices

Current Security Status

⚠️ Note: UCP is currently designed for trusted networks. For production use, consider:

  • Encryption: Add TLS/SSL support
  • Authentication: Implement user authentication
  • Authorization: Add access control
  • Rate Limiting: Prevent abuse
  • Input Validation: Sanitize all inputs

Recommended Security Measures

  1. Network Isolation: Deploy on private networks only
  2. Firewall Rules: Restrict access to known IPs
  3. File Validation: Validate file types and sizes
  4. Logging: Monitor for suspicious activity
  5. Updates: Keep Go and dependencies updated

Secrets Management

Environment Variables

Store sensitive data in environment variables:

# Use .env file (not committed to git)
UCP_SECRET_KEY=your-secret-key-here
UCP_ADMIN_PASSWORD=secure-password

Secret Rotation

# Rotate secrets
export UCP_SECRET_KEY=$(openssl rand -hex 32)
systemctl restart ucp-server

⚑ Performance

Performance Notes

  • Concurrency: Go's goroutines handle thousands of concurrent connections
  • Memory: Low memory footprint (~10-50MB per server instance)
  • CPU: Minimal CPU usage for typical workloads
  • Network: Optimized for local network speeds

Scaling Strategy

Horizontal Scaling

  • Deploy multiple server instances
  • Use load balancer for distribution
  • Each instance handles independent clients

Vertical Scaling

  • Increase server resources (CPU, RAM)
  • Adjust MAX_CLIENTS configuration
  • Optimize chunk size for network conditions

Caching

Currently, UCP doesn't implement caching. Future enhancements may include:

  • File chunk caching
  • Message history caching
  • Client connection pooling

πŸ“Š Monitoring & Logging

Activity Tracking

All server activity is automatically logged to logs/activity.log in JSON format.

Log Entry Format

{
  "timestamp": "2025-11-18T20:56:48Z",
  "type": "JOIN",
  "username": "Alice",
  "ip": "192.168.1.100:52341",
  "data": {
    "action": "joined"
  }
}

Activity Types

  • CONNECTION: Client connection/disconnection
  • JOIN: Client joined server
  • LEAVE: Client left server
  • MESSAGE: Chat message sent
  • FILE: File transfer chunk
  • ERROR: Error occurred

Querying Logs

# View recent activities
tail -f logs/activity.log

# Filter by username
grep '"username":"Alice"' logs/activity.log

# Filter by activity type
grep '"type":"FILE"' logs/activity.log

# Count activities
jq '.type' logs/activity.log | sort | uniq -c

Health Checks

Server Health

# Check if server is running
curl http://localhost:8080/health  # If health endpoint added

# Check process
ps aux | grep ucp-server

# Check port
netstat -an | grep 8080

Client Health

# Ping server from client
/ping

# Check connection status
/status

πŸ”§ Troubleshooting

Common Issues

1. Connection Refused

Symptoms:

Failed to connect to server: dial tcp: connect: connection refused

Solutions:

  • Verify server is running: ps aux | grep ucp-server
  • Check port availability: netstat -an | grep 8080
  • Verify firewall rules
  • Check server logs for errors

2. Username Already Taken

Symptoms:

Error: username Alice is already taken

Solutions:

  • Choose a different username
  • Wait for previous session to timeout
  • Check if another client is using the name

3. File Transfer Fails

Symptoms:

Failed to send file: file not found

Solutions:

  • Verify file path is correct
  • Check file permissions
  • Ensure sufficient disk space
  • Verify network stability

4. Network Timeout

Symptoms:

dial tcp: i/o timeout

Solutions:

  • Check network connectivity: ping <server-ip>
  • Verify firewall allows connections
  • Check server is accessible from client network
  • Increase timeout value

5. Chunk Errors

Symptoms:

Missing chunk 5 for file document.pdf

Solutions:

  • Retry file transfer
  • Check network stability
  • Verify server has sufficient resources
  • Check server logs for errors

Debugging

Enable Verbose Logging

Modify log level in code:

log.SetFlags(log.LstdFlags | log.Lshortfile)

Network Inspection

# Use Wireshark to inspect packets
wireshark -i eth0 -f "tcp port 8080"

# Use tcpdump
tcpdump -i any -n port 8080

Server Debug Mode

# Run with debug output
UCP_LOG_LEVEL=debug ./ucp-server

❓ FAQ

General

Q: What is UCP?
A: UCP (Unified Communication Protocol) is a lightweight protocol for chat messaging and file transfer over TCP.

Q: Is UCP secure?
A: UCP is designed for trusted networks. For production use, add TLS encryption and authentication.

Q: What platforms are supported?
A: Linux, macOS, and Windows. Any platform that supports Go.

Q: Can I use UCP over the internet?
A: Technically yes, but it's designed for local networks. Use VPN or add security features for internet use.

Technical

Q: What is the maximum file size?
A: No hard limit. Files are chunked into 64KB pieces, so any size is supported.

Q: How many clients can connect?
A: Default is 1000, but can be configured. Limited by system resources.

Q: Does UCP support encryption?
A: Not currently. TLS support is planned for future releases.

Q: Can I customize the chunk size?
A: Yes, modify ChunkSize constant in protocol/protocol.go.

Deployment

Q: How do I deploy on multiple servers?
A: Deploy multiple instances and use a load balancer, or run independent instances.

Q: Can I run server as a service?
A: Yes, use systemd (Linux), launchd (macOS), or NSSM (Windows).

Q: How do I backup logs?
A: Logs are in logs/activity.log. Use log rotation or backup scripts.


🀝 Contributing

We welcome contributions! Please follow these guidelines:

Branching Strategy

  • main: Production-ready code
  • develop: Development branch
  • feature/*: New features
  • bugfix/*: Bug fixes
  • hotfix/*: Critical fixes

Pull Request Process

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Ensure all tests pass
  6. Update documentation
  7. Submit pull request

Commit Style

Follow Conventional Commits:

feat: add TLS encryption support
fix: resolve connection timeout issue
docs: update README with deployment guide
test: add integration tests for file transfer
refactor: improve error handling

Code Review Checklist

  • Code follows Go style guidelines
  • Tests added/updated
  • Documentation updated
  • No breaking changes (or documented)
  • Performance considered
  • Security implications reviewed

Development Workflow

# 1. Create feature branch
git checkout -b feature/new-feature

# 2. Make changes
# ... edit files ...

# 3. Test changes
go test ./...
go build ./...

# 4. Commit
git add .
git commit -m "feat: add new feature"

# 5. Push
git push origin feature/new-feature

# 6. Create PR on GitHub

πŸ—ΊοΈ Roadmap

Short-Term (Next 3 Months)

  • Add TLS/SSL encryption support
  • Implement user authentication
  • Add rate limiting
  • Improve error messages
  • Add health check endpoint
  • Create web-based client interface

Mid-Term (3-6 Months)

  • Message persistence (database)
  • File compression
  • Multi-room/channel support
  • Mobile client applications
  • Admin dashboard
  • Metrics and monitoring

Long-Term (6-12 Months)

  • Distributed server architecture
  • End-to-end encryption
  • Voice/video support
  • Plugin system
  • API for third-party integrations
  • Cloud deployment options

πŸ“ Changelog

[1.0.0] - 2025-11-18

Added

  • Initial release
  • Real-time chat messaging
  • File transfer with chunking
  • Connection recovery
  • Activity tracking and logging
  • Network deployment support
  • Multi-client support
  • Keep-alive mechanism
  • Graceful shutdown

Changed

  • N/A (initial release)

Fixed

  • N/A (initial release)

Security

  • Basic error handling
  • Input validation

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License Summary

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.


πŸ™ Credits

Authors

Acknowledgments

  • Go community for excellent documentation and tools
  • Contributors and testers
  • Open source community

Dependencies

UCP is built with pure Go and has zero external dependencies (beyond the Go standard library).

Go Standard Library Packages Used:

  • net - Network operations
  • bufio - Buffered I/O
  • encoding/binary - Binary encoding
  • fmt - Formatting
  • log - Logging
  • os - Operating system interface
  • sync - Synchronization primitives
  • time - Time operations
  • strings - String manipulation
  • path/filepath - File path operations

πŸ“ž Support

Getting Help

  • GitHub Issues: Open an issue
  • Documentation: Check this README
  • Examples: See usage examples above

Reporting Bugs

When reporting bugs, please include:

  1. UCP version
  2. Operating system
  3. Steps to reproduce
  4. Expected behavior
  5. Actual behavior
  6. Logs (if applicable)

Feature Requests

We welcome feature requests! Please:

  1. Check if feature already exists
  2. Describe the use case
  3. Explain the expected behavior
  4. Consider implementation complexity

🌟 Star History

If you find UCP useful, please consider giving it a star on GitHub!


Made with ❀️ using Go

⬆ Back to Top

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages