websocket

command
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

websocket demonstrates a browser-friendly WebSocket route:

  • GET / serves a tiny HTML client.
  • WebSocket /ws uses middleware.WebSocketAuth for origin, token, and subprotocol checks.
  • Upgrade verification returns per-connection state as UserData.
  • Open subscribes each connection to a room.
  • Message publishes text frames to the other subscribers.

Run:

CGO_ENABLED=1 go run -tags gogo ./examples/websocket

Then open http://localhost:3004/ in a browser.

Or connect from the CLI:

websocat -H='Origin: http://localhost:3004' -H='Sec-WebSocket-Protocol: chat.v1' 'ws://localhost:3004/ws?name=cli&room=general&token=demo-local-token'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL