๐ฌ GoTalk
Real-time terminal chat powered by Go
Concurrent TCP connections โข Message broadcasting โข Server-side logging
Real-time terminal chat powered by Go.
Simple. Concurrent. Reliable.
Features โข Tech Stack โข Getting Started โข Usage โข Architecture
GoTalk is a TCP-based chat server written in Go that allows multiple users to communicate in real time through their terminals. It supports concurrent connections, unique usernames, timestamped messages, and persistent chat logs.
Designed as a networking-focused project, GoTalk demonstrates core concepts such as TCP communication, goroutines, channels, and synchronized message broadcasting.
GoTalk includes the following core features:
-
Real-Time Messaging ๐ฌ
Messages are delivered instantly to all connected users. -
Unique Usernames ๐ค
Each user must select a name that is not already in use. -
Timestamps โฐ
Every message includes the exact time it was sent. -
Chat Logs ๐
Messages and system events are stored in a log file for later review. -
Concurrent Connections ๐
Handles up to 10 users simultaneously using goroutines. -
Join / Leave Notifications ๐ช
Users are notified when someone enters or exits the chat. -
Message History ๐
Recent messages are displayed to users when they join.
- Go ๐น โ Core language, networking, and concurrency
- TCP/IP ๐ โ Reliable communication protocol
- Goroutines โก โ Concurrent client handling
- Channels ๐ก โ Message broadcasting and synchronization
- File I/O ๐พ โ Persistent chat logging
GoTalk provides a minimal yet functional chat experience over TCP connections, focusing on reliability and concurrency.
- Users โ Manage connections and enforce unique usernames
- Messages โ Broadcast messages with timestamps
- Events โ Handle join and leave notifications
- History โ Share recent messages with new users
The application uses simple data structures combined with Goโs concurrency model to ensure smooth operation.
- Go version 1.20 or newer
- A terminal to run the server and connect clients
-
Clone the repository:
git clone https://github.com/sahmedhusain/gotalk.git
-
Navigate to the project directory:
cd gotalk -
Install dependencies:
go mod tidy
-
Start the server:
go run main.go
Run the server first. Then connect using a TCP client such as Netcat.
The server listens on localhost:8989 by default.
nc localhost 8989You will see the server welcome screen and be prompted to enter a username:
Welcome to TCP-Chat!
_nnnn_
dGGGGMMb
@p~qp~~qMb
M|@||@) M|
@,----.JM|
JS^\__/ qKL
dZP qKRb
dZP qKKb
fZP SMMb
HZM MMMM
FqM MMMM
__| ". |\dS"qML
| `. | `' \Zq
_) \.___.,| .'
\____ )MMMMMP| .'
`-' `--'
[ENTER YOUR NAME]:
Enter a unique username (for example: Alice) to join the chat.
You will be prompted to enter a unique username before joining the chat.
go run main.go
Server is running on Port :8989[2024-10-12 15:12:45][system]: Alice joined the chat
[2024-10-12 15:13:02][Alice]: Hi Bob!
[2024-10-12 15:13:05][Bob]: Hello Alice!
[2024-10-12 15:14:00][system]: Bob has left our chat...
โโโโโโโโโโโโโ
โ Client โ
โ (Terminal)โ
โโโโโโโฌโโโโโโ
โ TCP
โโโโโโโผโโโโโโ
โ Server โ
โ (Go) โ
โโโโโโโโโโโโโค
โ Goroutine โโโโ
โ Goroutine โ โ Broadcast
โ Goroutine โโโโ Channel
โโโโโโโโโโโโโค
โ Logger โ โ chat_logs.txt
โโโโโโโโโโโโโ
- Each client runs in its own goroutine
- Messages flow through a central broadcast channel
- Chat activity is persisted using file-based logging
- Each client connection runs in its own goroutine
- Messages are sent through a central broadcast channel
- Connections โ Dedicated goroutines per client
- Broadcasting โ Central message dispatcher
- Logging โ File-based event and message logs
- Concurrency Safety โ Locks prevent race conditions
- Error Handling โ Graceful disconnect handling
- TCP sockets ensure reliable delivery
- Channel-based broadcasting improves performance
- Connection limits prevent overload
- Unique username validation
- Instant message delivery
- Persistent log storage (
chat_logs.txt) - Message history for new users
- Automated system messages
Contributions are welcome. Fork the repository, implement improvements, and submit a pull request.
This project is licensed under the MIT License. See LICENSE.md for details.
Built as part of a Go learning journey with a focus on networking, concurrency, and server-side development.
- Sayed Ahmed Husain โ [email protected]
- Qassim Aljaffer
- Building TCP servers in Go
- Using goroutines and channels effectively
- Concurrent client handling
- File-based logging
- Error handling in multi-user systems
- Maximum of 10 concurrent users
- No encryption (plain-text communication)
- Terminal-based interface only
- Add message encryption
- Improve terminal UI
- Develop a dedicated client
- Support private messaging
- Enhance scalability