Envelope is a basic chat server using TCP websockets.
Envelope broadcasts messages to all connected users.
Built with ❤️ in Paris
🙌 A huge thanks to @bitfield for his mentoring on this project. 🙌
Envelope can be run in two different ways :
- Using the provided Dockerfile to build a Docker image
- Importing the package and use the API within another Go Program
Requires Docker to be installed on your machine.
To build a Docker image and run it locally:
- Build the image:
docker build https://github.com/tgirier/envelope.git
- Run the container:
docker run -d -p 8080:8080 [YOUR-IMAGE-ID]
To import the API within your Go program, simply add the following statement to your go package:
import "github.com/tgirier/chat"
If to connect to your envelope server using nc, simply run:
nc <HOST> <PORT>
Example - if your envelope server is running locally on port 8080:
nc localhost 8080
If the connection is successful, the following welcome message will be displayed:
Welcome to envelope! Please enter your username:
Enter your username, press Enter. The notification will be boradcasted to all connected users:
<USERNAME> joined envelope
Then, simply enter your message and press Enter to send it to all connected users.
Requires the envelope package to be imported within your Go package
To create a new client connected to a given envelope server use ConnectClient. It takes the address of the target envelope server as a string:
client, err := envelope.ConnectClient(<SERVER_ADDRESS>)
Example - For a local server running on 8080:
client, err := envelope.ConnectClient("localhost:8080")
Next, the server will send the welcome message and ask for the username. To handle it, simply use the Read method on the newly created client:
client.Read()
Next, the server will expect a username. Send the username using the Send method:
client.Send("<USERNAME>"+"\n")
Then the client can send messages or read them using the provided methods.