TCPChat is a command-line application that implements a Server-Client Architecture similar to NetCat (nc) command. It allows multiple clients to connect to a server and participate in a group chat. The application supports TCP connections, requires clients to provide a name, and provides control over the number of connections allowed.
- TCP Connection: The server establishes a TCP connection and acts as a central hub for multiple clients to connect to.
- Client Name: Each client is required to provide a unique name when connecting to the server.
- Control Connections: The server can control the number of client connections allowed. This TCP chat allows up to 10 connections
- Chat Messaging: Clients can send messages to the chat, which are broadcasted to all other connected clients.
- Non-Empty Messages: Empty messages from clients are not broadcasted to the chat.
- Message Timestamp: Each message sent to the chat is identified with the timestamp and the name of the client who sent it. The format is:
[YYYY-MM-DD HH:MM:SS][client.name]: [client.message]
. - Message History: When a new client joins the chat, they receive the entire history of previously sent messages.
- Client Notifications: When a client connects or disconnects, the server notifies all other clients about the event.
- Message Broadcasting: All clients receive messages sent by other clients in real-time.
- Default Port: If no port is specified, the default port 8989 is used. If an incorrect usage is provided, the program displays the usage message:
[USAGE]: ./TCPChat $port
.
To use TCPChat, follow these steps:
- Clone the repository or download the project files.
- Compile the code if necessary.
- Run the server by executing the following command:
Replace
go run . [port]
[port]
with the desired port number. If no port is specified, the default port 8989 will be used. - Connect clients to the server by executing the following command on each client:
Replace
nc [server_ip] [port]
[server_ip]
with the IP address or hostname of the server, and[port]
with the corresponding port number. - Clients will be prompted to enter their name upon connection. Remeber that client's name must be between 1 and 20 characters long.
- Start chatting with other connected clients by typing messages and pressing Enter. Messages should not exceed the length of 200 characters.
Here are some examples of how to use TCPChat:
-
Run the server on the default port (8989):
go run .
-
Run the server on a specific port:
go run . [port]
-
Connect a client to the server:
nc localhost [port]
TCPChat does not have any external dependencies. It is built using standard networking libraries available in the programming language used.