Skip to content
ElenaChanouPublic

About

Concurrent TCP group chat server built in Go replicating NetCat with Goroutines, thread-safe broadcast channels, and multi-room isolation.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

TCPChat (NetCat Clone)

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.

🚀 Core Features

  • 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.Mutex locking 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.

🌟 Bonus Features Implemented

  1. Multiple Chat Rooms: Clients are prompted to join a specific "Room" upon connecting. Broadcasts, chat history, and name uniqueness are securely isolated per room.
  2. 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.
  3. Activity Logging: The server logs all detailed client activities (joining, leaving, changing names, broadcasting messages).
  4. Persistent Logs: All server logs are dual-written to the standard output and permanently saved in a local server_logs.txt file.
  5. NetCat CLI Flags:
    • -p <port>: Specify the listening port.
    • -v: Enable verbose background logging.
    • -h: Display the help menu.

🛠️ Usage

Starting the Server

You can start the server by simply providing a port number:

go run . 8989

Or using the advanced NetCat-style flags:

go run . -v -p 8989

Connecting as a Client & Using the App

Open a new terminal window and use the standard nc command to connect to the server:

nc localhost 8989

Login Flow

  1. Welcome Screen: Upon connecting, the server will display the project's ASCII logo.
  2. Choose Name: You will be prompted with [ENTER YOUR NAME]:. Type your desired alias and press Enter.
  3. 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).
  4. Validation: If your chosen name is already taken inside that specific room, the server will ask you to provide a different name.

Chatting & Commands

  • 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.

🧪 Testing

The project includes unit tests for verifying core functionality and string formatting. Run all tests using:

go test ./...

About

Concurrent TCP group chat server built in Go replicating NetCat with Goroutines, thread-safe broadcast channels, and multi-room isolation.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages