GoChat is a simple command-line chat application written in Go. It allows two users to communicate over a local network or the internet. The application supports both text messaging and file transfers.
- Real-time Messaging: Send and receive messages in real-time.
- File Transfer: Send files to your chat partner.
- Simple Configuration: Configure the server and ports using a
config.jsonfile. - Cross-Platform: Works on Windows, macOS, and Linux.
- Go installed on your machine (version 1.16 or higher recommended).
- Clone the repository:
git clone https://github.com/yourusername/gochat.git
- Navigate to the project directory:
cd gochat - To install dependencies, run the following command:
go mod tidy
-
Edit the
config.jsonfile to set the server address and ports:{ "your_server": "0.0.0.0", "your_port": 8080, "friend_server" : "0.0.0.0" "friend_port": 8000 }your_server: The IP address or hostname of your server. Uselocalhostfor local testing.your_port: The port on which your server will listen for incoming connections.friend_server: The IP address or hostname of friend server. Uselocalhostfor local testing.friend_port: The port on which your friend's server is listening. This is where your client will connect.
-
Make sure the
your_portandfriend_portvalues are different for each user to avoid conflicts.
Using command line:
- Start the chat application:
go run chat.go
- Enter your name when prompted.
- The application will attempt to connect to your friend's chat instance. If the connection is successful, you can start chatting.
Using script
- run this command on you terminal
this command create two terminals and run chat with correct configs on each one of them. Use
chmod +x run_chat.sh ./run_chat.sh
ctrl+Dto stpo terminals
- Type your messages in the terminal and press
Enterto send them. - To exit the chat, type
exit.
To send a file, use the following command in the chat:
<SEND /path/to/your/file>
The file will be sent to your chat partner, and they will receive it in the same directory where their chat application is running.
-
User A starts the chat application:
go run chat.go
- Uses
your_port: 8080andfriend_port: 8000. - Enters name:
Alice.
- Uses
-
User B starts the chat application:
go run chat.go
- Uses
your_port: 8000andfriend_port: 8080. - Enters name:
Bob.
- Uses
-
Alice and Bob can now chat and send files to each other.
gochat
├── chat.go
├── client
│ ├── client.go
│ └── colors.go
├── config.json
├── go.mod
├── go.sum
├── main_test.go
├── README.md
├── run_chat.sh
└── server
└── server.go
- chat.go: The main entry point of the application. It handles the configuration and starts the client and server.
- client/client.go: Contains the client logic for sending messages and files.
- server/server.go: Contains the server logic for receiving messages and files.
- config.json: Configuration file for setting the server address and ports.