Skip to content

meljanat/net-cat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Net-Cat (TCP Chat Server)

Description

This project is a recreation of the NetCat utility in a Server-Client Architecture, specifically designed to function as a group chat application. It runs a server listening on a specified TCP port for incoming connections, allowing multiple clients to connect, choose a username, and exchange messages in real-time.

Features

  • TCP Architecture: Establishes a reliable TCP connection between the server and multiple clients (1-to-many relationship).
  • Concurrency: Handles multiple client connections concurrently using Go-routines and ensures data safety with Mutexes.
  • Connection Throttling: Restricts the server to a maximum of 10 concurrent client connections to prevent overload.
  • Custom Usernames: Clients are required to provide a valid, unique, ASCII-only username (1-16 characters) upon joining. Clients are given 3 attempts to provide a valid name.
  • Chat History: New clients are automatically sent the entire chat history upon successfully joining the group.
  • Real-time Notifications: The server broadcasts informative messages to all connected clients when a new user joins or an existing user leaves the chat.
  • Message Formatting: All messages are strictly formatted with a timestamp and the sender's username (e.g., [2020-01-20 15:48:41][client.name]:[client.message]). Empty messages are ignored and not broadcasted.
  • Resilience: If a client leaves the chat, the server and other connected clients remain active and unaffected.
  • Default Port: If no port is specified during execution, the server defaults to listening on port 8989.

Prerequisites

  • Go: Version 1.22.3 or higher.

Installation & Usage

Starting the Server

You can start the server by navigating to the project directory and running the Go application. You can specify a port or leave it blank to use the default (8989).

# Using the default port (8989)
$ go run .
Listening on port :8989

# Using a custom port
$ go run . 2525
Listening on port :2525

Note: If you provide more than one argument, the program will respond with the usage message: [USAGE]: ./TCPChat $port

Connecting Clients

Clients can connect to the server using the standard nc (NetCat) command.

$ nc localhost 2525

Upon connecting, you will be greeted with a Linux logo and prompted to enter your name:

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]:

Project Structure

  • server.go: The main entry point of the application. It parses arguments and starts the server.
  • funcs/definePort.go: Handles command-line argument parsing to determine the listening port.
  • funcs/startServer.go: Initializes the TCP listener, accepts incoming client connections, checks the 10-client limit, and spawns a new Go-routine for each accepted connection.
  • funcs/handleConn.go: Manages individual client sessions. It handles the initial welcome message, name registration, chat history transmission, message broadcasting, and disconnection events.
  • funcs/checkInput.go: Contains validation logic to ensure usernames are the correct length (1-16 characters), consist of printable ASCII characters, and are not already taken by another active user.
  • wlcm.txt: Contains the ASCII art logo displayed to users upon connecting.

Allowed Packages

This project strictly adheres to using only standard Go libraries: io, log, os, fmt, net, sync, time, bufio, errors, strings, and reflect.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages