This project recreates the functionality of NetCat in a Server-Client architecture. It runs in server mode, listening for incoming connections on a specified port, and can be used in client mode to connect to the server and transmit information. The project emulates the NetCat utility, which reads and writes data across network connections using TCP.
The server-client application includes the following features:
- TCP connection between a server and multiple clients (one-to-many relation).
- A requirement for clients to provide a name upon connection.
- Control over the number of simultaneous connections (up to 10).
- Clients can send messages to the chat.
- Empty messages are not broadcasted.
- Messages are timestamped and prefixed with the sender’s name.
- New clients receive all previous messages upon joining.
- All clients are notified when a new client joins or leaves.
- Clients that leave do not cause other clients to disconnect.
- The server defaults to port 8989 if no port is specified; otherwise, it shows a usage message.
Run the server with default port:
$ go run .
Listening on port :8989Run the server with a specified port:
$ go run . 2525
Listening on port :2525If no port is specified, or if incorrect usage is attempted, the program will display:
[USAGE]: ./TCPChat [port]Start the server on the default port:
$ go run .
Listening on port :8989To connect a client using nc (NetCat):
$ nc localhost 8989Upon connection, you will see:
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]:
After entering a valid name, you can start sending messages. Other clients connected to the server will see these messages with timestamps and the sender’s name.