TCPChat is a concurrent TCP-based group chat server written in Go. It operates similarly to the standard nc (NetCat) command-line utility, allowing multiple clients to connect to a centralized chat server, broadcast messages, and interact in real-time.
- TCP Server-Client Architecture: Built entirely on standard Go library packages (
net,sync, etc.). - High Concurrency: Handles multiple simultaneous connections using Goroutines.
- Connection Limiting: Restricts the server to a maximum of 10 concurrent connections.
- Thread Safety: Employs strict
sync.Mutexlocking to completely eliminate data races. - Seamless UX: Dynamically manages the client's command prompt (
[YYYY-MM-DD HH:MM:SS][Name]:) so that incoming broadcasts don't interrupt active typing. - Room History: Automatically replays previous messages to newly connected clients.
- Multiple Chat Rooms: Clients are prompted to join a specific "Room" upon connecting. Broadcasts, chat history, and name uniqueness are securely isolated per room.
- Dynamic Name Changing: Users can change their alias on-the-fly without disconnecting by typing
/name [NewName]. The server instantly broadcasts a notification to the rest of the room. - Activity Logging: The server logs all detailed client activities (joining, leaving, changing names, broadcasting messages).
- Persistent Logs: All server logs are dual-written to the standard output and permanently saved in a local
server_logs.txtfile. - NetCat CLI Flags:
-p <port>: Specify the listening port.-v: Enable verbose background logging.-h: Display the help menu.
You can start the server by simply providing a port number:
go run . 8989Or using the advanced NetCat-style flags:
go run . -v -p 8989Open a new terminal window and use the standard nc command to connect to the server:
nc localhost 8989- Welcome Screen: Upon connecting, the server will display the project's ASCII logo.
- Choose Name: You will be prompted with
[ENTER YOUR NAME]:. Type your desired alias and press Enter. - Choose Room: You will then be prompted with
[ENTER ROOM NAME]:. Type the name of the room you wish to join (e.g.,General,Lobby). - Validation: If your chosen name is already taken inside that specific room, the server will ask you to provide a different name.
- Send Messages: Simply type your message and press Enter. Your message will be broadcast to everyone in the room alongside a timestamp.
- Change Name: You can change your alias at any time without leaving the room by typing
/name [NewName]and pressing Enter.
The project includes unit tests for verifying core functionality and string formatting. Run all tests using:
go test ./...