⚠️ WARNING - CRITICAL INFRASTRUCTURE
This repository is designed to facilitate communication for Iranian citizens during protests and internet shutdowns. It operates on domestic servers to maintain connectivity when external internet access is restricted or censored. Use responsibly and ensure secure deployment in sensitive environments.
A feature-rich TCP chat application built in Go with user registration and file sharing capabilities, designed for resilient local network communication.
- User Registration - Register users with first and last name
- Real-time Messaging - Instant messaging between connected users
- File Sharing - Upload and share files (images, videos, documents)
- Multi-Client Support - Support for multiple simultaneous users
- TCP Server - Chat server on port 8080
- HTTP File Server - File upload server on port 8081
- Dockerized - Ready for deployment with Docker and Docker Compose
- Offline-First - Works on local networks without internet connectivity
├── server.go # Chat and file upload server code
├── client.go # Client code with registration and upload
├── Dockerfile # Docker image for server and client
├── docker-compose.yml # Service configuration
├── go.mod # Go module file
├── go.sum # Dependency checksums
└── README.md # Project documentation
- Go 1.21 or later
- Docker (optional - for containerized deployment)
- Docker Compose (optional)
# Build
go build -o chat-server ./server.go
# Run
./chat-serverThe server runs on two ports:
- Port 8080: TCP Chat Server
- Port 8081: HTTP File Upload Server
# Build
go build -o chat-client ./client.go
# Run
./chat-clientUpon running, you will be prompted for:
- First name
- Last name
Simply type your message and press Enter:
Hello everyone!
Use the /upload command:
/upload /path/to/your/file.jpg
Notes:
- Image files:
.jpg,.png,.gif,.webp(displayed as image) - Video files:
.mp4,.mov,.webm(displayed as video) - Other files: displayed as file
- Maximum file size: 50MB
docker-compose builddocker-compose updocker-compose downThe server consists of two main components:
-
TCP Server (Port 8080)
- Manages client connections
- User registration
- Broadcasts messages to all connected users
-
HTTP Server (Port 8081)
- Receives and stores files in
uploads/directory - Serves uploaded files
- Generates URLs for file access
- Receives and stores files in
// Registration
{
"type": "register",
"first": "John",
"last": "Doe"
}
// Text Message
{
"type": "text",
"text": "Your message here"
}
// Media Message
{
"type": "media",
"url": "http://localhost:8081/uploads/file.jpg",
"mediaType": "image|video|file"
}
// Info Message (from server)
{
"type": "info",
"text": "Information message"
}In client.go:
conn, err := net.Dial("tcp", "localhost:8080")In server.go:
err := r.ParseMultipartForm(50 << 20) // 50MB - you can change thisThe project includes GitHub Actions workflow for:
- Building Go binaries
- Running tests
- Building Docker images
- Deployment (optional)
Some development ideas:
- Chat Rooms - Create multiple channels
- Message Encryption - Enhanced security for data transmission
- Message History - Store messages in database
- WebSocket Support - Web browser compatibility
- Private Messages - Direct messaging between two users
- Notifications - Alerts for new messages
- Authentication - Login system with passwords
- End-to-End Encryption - For maximum privacy in sensitive communications
// Server Components
- handleConnection() // Manage connections
- broadcast() // Broadcast messages to all
- uploadHandler() // Handle file uploads
// Client Components
- uploadFile() // Upload file
- detectMediaType() // Detect media type# Make sure the server is running
ps aux | grep server.go- Check file size (maximum 50MB)
- Enter the correct file path
- Make sure HTTP server is running on port 8081
# Find process on port 8080 or 8081
lsof -i :8080
lsof -i :8081
# Kill the process
kill -9 <PID>Register:
{"type": "register", "first": "Ali", "last": "Ahmadi"}Send Text:
{"type": "text", "text": "Hello World"}Send Media:
{"type": "media", "url": "http://...", "mediaType": "image"}Upload File:
curl -X POST http://localhost:8081/upload \
-F "file=@/path/to/file.jpg"Response:
{"url": "http://localhost:8081/uploads/1234567890.jpg"}Contributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
Built with ❤️ using Go
This project is licensed under the MIT License.