A simple, TCP-based chat application implemented in Go. It features both client and server modes, allowing multiple clients to connect, send messages, and interact with each other in real-time. The application supports private messaging between users and basic commands like listing users or exiting the session.
- Client-Server Architecture: Clients connect to a central server and can send messages to each other.
- Private Messaging: Send messages directly to other users using
@username
format. - Basic Commands: List available users, get help, or exit the chat.
- Thread-Safe Client Management: The server safely handles multiple concurrent clients.
- Go: Ensure you have Go installed. This project uses Go version 1.22.7. You can download it from the official Go website.
sudo dnf install go
-
Clone the repository:
git clone https://github.com/fuseraft/gochat.git cd gochat
-
Build the project:
go build -o gochat
You can run the application in two modes: server
or client
.
-
Start the server by specifying the address and port:
./gochat --server <host-address:port>
Example:
./gochat --server 127.0.0.1:8080
-
The server will listen for incoming connections from clients.
-
Connect a client to the server by specifying the address and port of the running server:
./gochat --client <host-address:port>
Example:
./gochat --client 127.0.0.1:8080
-
Once connected, you will be prompted to enter a username:
username> yourname
-
You can now start sending messages or using commands.
- @username message: Send a private message to
username
. - @all message: Send a message to every connected user.
- users: List all connected users.
- help: Display a help message with available commands.
- exit: Exit the chat session.
-
Running the server:
./gochat --server localhost:12345
Output:
Server is listening on localhost:12345...
-
Connecting a client:
./gochat --client localhost:12345
Output:
Connected to server. username> alice >
-
Sending a message:
@bob Hello Bob!
-
Listing users:
users
Output:
users: alice, bob
-
Exiting the chat:
exit