A lightweight terminal-based TCP chat server written in Go
Features • Installation • Usage • Commands • Contributing
Net-Cat is a real-time messaging server designed for terminal enthusiasts. It supports multiple concurrent clients, colored output, private mentions, and essential chat commands—all through a simple TCP connection.
- 💬 Real-time messaging between multiple clients
- 👥 Single chat room (all clients communicate together)
- 🎨 ANSI-colored interface for enhanced readability
- 📜 Chat history automatically sent to new joiners
- 🔒 Input validation for usernames and messages
- ⚡ Concurrent handling using Go goroutines
- 🎯 Private mentions with
@usernamesyntax - 🛠️ User commands for renaming and listing users
- Go 1.20 or higher
- Git
- Terminal with TCP client (
ncortelnet)
# Clone the repository
git clone https://github.com/chentaymane/net-cat.git
# Navigate to project directory
cd net-cat
# Build the executable
go build -o net-cat main.goRun the server with default port (8989):
./net-catOr specify a custom port:
./net-cat 8080Output:
Listening on the port :8080
Use netcat to connect:
nc localhost 8080You'll be greeted with:
Welcome to TCP-Chat!
_nnnn_
dGGGGMMb
@p~qp~~qMb
M|@||@) M|
@,---.JM|
JS^\__/ qKL
dZP qKb
dZP qKb
fZP SMMb
HZM MMMM
FqM MMMM
__| ". |\dS"qML
| `. | `' \Zq
_) \.___.,| .'
\____ )MMMMMP| .'
`-' `--'
[ENTER YOUR NAME]:
| Command | Description | Example |
|---|---|---|
/rename <new_name> |
Change your display name | /rename RedFox |
/users |
List all connected users | /users |
@username <message> |
Send a private mention | @achent Hey there! |
[ENTER YOUR NAME]: achent
[2026-01-17 20:50:25][achent]: Hello everyone!
karim has joined our chat...
[2026-01-17 20:50:48][karim]: @achent Hi there!
[2026-01-17 20:51:00][achent]: /rename RedFox
[2026-01-17 20:51:10][RedFox]: Welcome back!
[2026-01-17 20:52:05][karim]: /users
Connected users:
- RedFox
- karim
type Client struct {
conn net.Conn // TCP connection
name string // Unique username
}| Function | Purpose |
|---|---|
HandleClient |
Manages individual client connections in separate goroutines |
broadcast |
Sends messages to all clients except the sender |
Tag |
Delivers private mentions to specific users |
Add |
Safely Add new clients |
Remove |
Safely removes disconnected clients |
Rename |
Updates client usernames with validation |
sendPrompt |
Displays timestamped input prompts |
validName |
Validates usernames (alphanumeric, max 10 chars) |
validMsg |
Validates messages (safe characters, max 100 chars) |
- Goroutines handle multiple clients simultaneously
- sync.RWMutex protects shared resources (client map, chat history)
- Thread-safe operations for all client management
net-cat/
│
├── main.go # Entry point, TCP listener
├── functions/ # Core chat functionality
│ ├── broadcast.go # Message broadcasting logic
│ ├── handleclient.go # Client connection handling
│ ├── Client.go # Client functions
│ ├── sub-functions.go # Helper functions & utilities
│ └── vars.go # Shared variables & types
├── go.mod # Go module definition
└── README.md # This file
- Alphanumeric characters only
- Maximum 10 characters
- Must be unique
- No special characters or spaces
- Maximum 100 characters
- Only safe ASCII characters allowed
- No control characters or malicious input
Contributions are welcome! Follow these steps:
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Commit your changes
git commit -m 'Add amazing feature' - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
- Go 1.20+
- Terminal with ANSI color support
- Network connectivity (localhost or LAN)
- Multiple chat rooms
- Persistent chat history (database)
- User authentication
- File sharing support
- TLS/SSL encryption
- Web-based client interface
achent ahaddou
- GitHub: @chentaymane / @mrshD3IM05
- Project: net-cat
- Currently supports single chat room only
- Requires terminal with ANSI escape code support
- Designed for local network or localhost use
- Lightweight and easy to extend
Built with ❤️ using Go
⭐ Star this repo if you find it useful!