This project is a simple WebSocket server implemented in Go. It serves HTML files and handles WebSocket connections for clients and monitors.
- Serve HTML files (
index.htmlandclient.html) using Go'sembedpackage. - Handle WebSocket connections for clients and monitors.
- Broadcast messages to connected clients and monitors.
- Support for connecting and disconnecting events.
- Go 1.16 or later
- Gorilla WebSocket package
- Clone the repository:
git clone https://github.com/yourusername/socket-test.git cd socket-test
-
Set the environment variable for the server port (optional):
export S_PORT=8082 -
Run the server:
go run main.go
-
Open your browser and navigate to
http://localhost:8082to access the home page.
/- Serves theindex.htmlfile./client- Serves theclient.htmlfile./ws- Handles WebSocket connections.
connect- Triggered when a client or monitor connects.disconnect- Triggered when a client or monitor disconnects.message- Handles messages sent by clients or monitors.
To run tests, use the following command:
go test ./...