Documentation
¶
Overview ¶
Package ws implements RFC 6455 WebSocket framing with zero external dependencies. Only the server side (upgrade + read/write frames).
This is a minimal, auditable implementation — ~200 LOC. It handles text frames, close frames, and ping/pong. Fragmentation is not supported (every frame is FIN=true), which is fine for JSON messages.
Index ¶
Constants ¶
const ( OpText = 0x1 OpBinary = 0x2 OpClose = 0x8 OpPing = 0x9 OpPong = 0xA )
Opcodes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn wraps a net.Conn with WebSocket framing.
func Upgrade ¶
Upgrade performs the WebSocket upgrade handshake and returns a Conn. The ResponseWriter is hijacked — do not use it after calling Upgrade.
func (*Conn) ReadMessage ¶
ReadMessage reads a complete message from the WebSocket connection. Returns the opcode and payload. For text messages (opcode 0x1), the payload is a UTF-8 string. This is a blocking call.