Skip to content

2001basta/net-cat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TCPChat

TCPChat is a Go-based implementation of a simple chat system using a Server-Client architecture, inspired by the NetCat utility. This project creates a group chat where multiple clients can connect to a server, send messages, and receive updates in real-time.

Objectives

The goal of this project is to recreate the functionalities of NetCat in a chat application that supports the following features:

TCP Connection: Establish a TCP connection between a server and multiple clients (one-to-many relationship). Client Naming: Each client must provide a unique name upon connection. Connection Control: The server should manage a maximum of 10 concurrent connections. Message Handling: Clients can send messages that are timestamped and prefixed with the sender's name. Message Synchronization: New clients joining the chat should receive all previous messages. Join/Leave Notifications: The server should notify all clients when a new client joins or when a client leaves. Non-Empty Messages: Empty messages should not be broadcasted to other clients. Default Port: If no port is specified, the application defaults to port 8989. Requirements Language: Go Concurrency: Utilize Go-routines for handling concurrent connections. Synchronization: Use channels or mutexes to manage concurrent access and communication. Error Handling: Properly handle errors on both server and client sides. Testing: Implement unit tests for both server and client functionalities. Good Practices: Follow Go best practices for clean and maintainable code.

Installation

Clone the Repository:

git clone https://learn.zone01oujda.ma/git/oelhaouc/net-cat.git
cd net-cat

Build the Project:

go build -o TCPchat

Usage Start the Server:

./TCPchat [port]

If no port is specified, the server will listen on port 8989. Connect Clients:

nc [server_ip] [port]

Upon connection, the client will be greeted with a Linux logo and prompted to enter their name. Client Interaction:

Clients can send messages, and they will be displayed to all connected clients in the format:

[YYYY-MM-DD HH:MM:SS][client.name]:[client.message]

Messages are timestamped and include the sender’s name. Join/Leave Notifications:

When a client joins or leaves, the server will notify all other connected clients.

Example

Server:

$ ./TCPchat 2525
Listening on the port :2525

Client 1 (Yenlik):

$ nc localhost 2525
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]: Yenlik
[2020-01-20 16:03:43][Yenlik]:hello
[2020-01-20 16:03:46][Yenlik]:How are you?
[2020-01-20 16:04:10][Yenlik]:
Lee has joined our chat...
[2020-01-20 16:04:15][Yenlik]:
[2020-01-20 16:04:32][Lee]:Hi everyone!
[2020-01-20 16:04:32][Yenlik]:
[2020-01-20 16:04:35][Lee]:How are you?
[2020-01-20 16:04:35][Yenlik]:great, and you?
[2020-01-20 16:04:41][Yenlik]:
[2020-01-20 16:04:44][Lee]:good!
[2020-01-20 16:04:44][Yenlik]:
[2020-01-20 16:04:50][Lee]:alright, see ya!
[2020-01-20 16:04:50][Yenlik]:bye-bye!
[2020-01-20 16:04:57][Yenlik]:
Lee has left our chat...
[2020-01-20 16:04:59][Yenlik]:

Client 2 (Lee):

$ nc localhost 2525
Yenliks-MacBook-Air:simpleTCPChat ybokina$ nc localhost 2525
Yenliks-MacBook-Air:simpleTCPChat ybokina$ nc localhost 2525
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]: Lee
[2020-01-20 16:03:43][Yenlik]:hello
[2020-01-20 16:03:46][Yenlik]:How are you?
[2020-01-20 16:04:15][Lee]:Hi everyone!
[2020-01-20 16:04:32][Lee]:How are you?
[2020-01-20 16:04:35][Lee]:
[2020-01-20 16:04:41][Yenlik]:great, and you?
[2020-01-20 16:04:41][Lee]:good!
[2020-01-20 16:04:44][Lee]:alright, see ya!
[2020-01-20 16:04:50][Lee]:
[2020-01-20 16:04:57][Yenlik]:bye-bye!
[2020-01-20 16:04:57][Lee]:^C

Acknowledgements

Inspired by NetCat and its functionalities. Special thanks to the Go community for their support and libraries.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages