This is a simple chat server implemented in Go, using WebSockets for real-time communication. It is made to be anonymous if wanted, and no data is being saved to a database, which makes it both lightweight and secure. It allows multiple clients to connect and exchange messages.
This project is primarily made for IM at Elvebakken Upper Secondary School, and hosted at a VM on our server. The downside of this, is that it can only be accessed to people on the same network as the VM, or by using a VPN. You could open a port to the public, but for security reasons, I chose to have it run locally on our network.
This is the server side part of the IM-cli-chat project. The client side repo is here.
- Have Docker installed on your system. (If you choose to deploy using docker, which is recommended)
- Have go version 1.22.1 (may work on different versions) installed on your system. (If you choose to deploy using go)
- Have git installed on your system.
- Use a terminal with a Unix shell concept that derives from Bourne shell (Linux, MacOS). If you use Windows, you may need to use WSL in order to follow the guide.
- Clone this repo (
git clone https://github.com/ivermoka/IM-cli-chat-server
)
- Build an image (
sudo docker build -t im-cli-chat-server .
) - Run using your recently built image (
sudo docker run -d -p 8080:8080 im-cli-chat-server
)
- Make sure to be in the correct directory
- (Not recommended) You can just run the go program like normal, but then the program will stop once you close your terminal window (
go run .
orgo build . ./your_executable_name
) - (Recommended) Use nohup to run the program detatched (
nohup go run .
). If you need to check if the process is running, you can useps aux | grep program_name
. The numbers next to your user is the process ID. If you need to kill process, usekill your_process_id(PID)
(you find the ID with the previous command). PS: after thenohup
command has been written, be sure to exit the terminal tab in order to not kill process accidentally.
The server will start running on port 8080 by default.
- Clients can connect to the server using a WebSocket connection.
- Once connected, clients can send messages to the server, which will be broadcasted to all connected clients.
- I have also made a client side program: IM-cli-chat, which can be used to connect to this program.
- WebSocket-based communication
- Real-time messaging
- Seeing amount of peers connected (not usable when running a detached program)
- CLI program (used in terminal)
- gorilla/websocket: A WebSocket implementation for Go.
Contributions are welcome! If you'd like to contribute to this project, feel free to open an issue or submit a pull request.