examples/using-web-socket/Readme.md
This example demonstrates how to create and handle a WebSocket connection using the GoFr framework. It covers establishing the connection, receiving messages from the client, and sending responses back to the client in real time.
The /ws endpoint in this example:
"Hello! GoFr").This is useful for building real-time applications such as chat systems, dashboards, and live notifications.
Clone the repository and navigate to the example folder:
git clone https://github.com/gofr-dev/gofr.git
cd gofr/examples/using-web-socket
Start the application:
go run main.go
This will start the server on:
ws://localhost:8001/ws
app := gofr.New()
app.WebSocket("/ws", WSHandler)
app.Run()
/ws route for WebSocket connections."Hello! GoFr" back to the client.The example includes a test file main_test.go which:
gorilla/websocket client.Run the test:
go test -v
Expected output:
=== RUN Test_WebSocket_Success
--- PASS: Test_WebSocket_Success (0.10s)
PASS
Using wscat:
npm install -g wscat
wscat -c ws://localhost:8001/ws
> Hello from Client
< Hello! GoFr