Skip to content

A simple TCP-based chat server implemented in Go that enables real-time communication between multiple clients. Features include message broadcasting, unique client naming, timestamped messages, and chat history logging. Built with goroutines for concurrency and TCP sockets for networking.

License

Notifications You must be signed in to change notification settings

sahmedhusain/gotalk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

32 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

GoTalk ๐Ÿ’ฌ

Go License


๐Ÿ’ฌ 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


Overview

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.


โœจ Features

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.


๐Ÿ› ๏ธ Technologies Used

  • 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


๐ŸŽฏ Project Objective

GoTalk provides a minimal yet functional chat experience over TCP connections, focusing on reliability and concurrency.

Core Responsibilities

  1. Users โ€“ Manage connections and enforce unique usernames
  2. Messages โ€“ Broadcast messages with timestamps
  3. Events โ€“ Handle join and leave notifications
  4. History โ€“ Share recent messages with new users

The application uses simple data structures combined with Goโ€™s concurrency model to ensure smooth operation.


๐Ÿš€ Getting Started

Prerequisites

  • Go version 1.20 or newer
  • A terminal to run the server and connect clients

Installation & Setup

  1. Clone the repository:

    git clone https://github.com/sahmedhusain/gotalk.git
  2. Navigate to the project directory:

    cd gotalk
  3. Install dependencies:

    go mod tidy
  4. Start the server:

    go run main.go

๐Ÿ“– How to Use

Run the server first. Then connect using a TCP client such as Netcat.
The server listens on localhost:8989 by default.

Example Client Connection

nc localhost 8989

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


๐Ÿ’ป Terminal Examples

Starting the Server

go run main.go
Server is running on Port :8989

Chat Session Example

[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!

User Leaving

[2024-10-12 15:14:00][system]: Bob has left our chat...

๐Ÿ› ๏ธ Application Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Client   โ”‚
โ”‚ (Terminal)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
      โ”‚ TCP
โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Server   โ”‚
โ”‚   (Go)    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Goroutine โ”‚โ”€โ”€โ”
โ”‚ Goroutine โ”‚  โ”‚ Broadcast
โ”‚ Goroutine โ”‚โ”€โ”€โ”˜ Channel
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Logger   โ”‚ โ†’ chat_logs.txt
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Design Overview

  • Each client runs in its own goroutine
  • Messages flow through a central broadcast channel
  • Chat activity is persisted using file-based logging

Data Handling

  • Each client connection runs in its own goroutine
  • Messages are sent through a central broadcast channel

Server-Side Design

  • 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

Networking

  • TCP sockets ensure reliable delivery
  • Channel-based broadcasting improves performance
  • Connection limits prevent overload

๐Ÿ“‹ Chat System Details

  • Unique username validation
  • Instant message delivery
  • Persistent log storage (chat_logs.txt)
  • Message history for new users
  • Automated system messages

๐Ÿค Contributing

Contributions are welcome. Fork the repository, implement improvements, and submit a pull request.


๐Ÿ“„ License

This project is licensed under the MIT License. See LICENSE.md for details.


๐Ÿ™ Acknowledgments

Built as part of a Go learning journey with a focus on networking, concurrency, and server-side development.


๐Ÿ‘ฅ Authors


๐Ÿ“š What I Learned

  • Building TCP servers in Go
  • Using goroutines and channels effectively
  • Concurrent client handling
  • File-based logging
  • Error handling in multi-user systems

โš ๏ธ Limitations

  • Maximum of 10 concurrent users
  • No encryption (plain-text communication)
  • Terminal-based interface only

๐Ÿ”ฎ Future Improvements

  • Add message encryption
  • Improve terminal UI
  • Develop a dedicated client
  • Support private messaging
  • Enhance scalability

About

A simple TCP-based chat server implemented in Go that enables real-time communication between multiple clients. Features include message broadcasting, unique client naming, timestamped messages, and chat history logging. Built with goroutines for concurrency and TCP sockets for networking.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •