ws_coder

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ws_coder provides an optional WebSocket backend with compression, message size limits and RFC 6455 close handshakes.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected     = errors.New("socket connection is not initialized")
	ErrAlreadyConnected = errors.New("socket connection is already connecting or connected")
)

Functions

This section is empty.

Types

type Option

type Option func(*WebSocketConnection) error

func WithCompression

func WithCompression(mode websocket.CompressionMode) Option

WithCompression enables negotiation of permessage-deflate with the peer.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient uses client for the HTTP upgrade request, allowing custom TLS, proxy, cookie and timeout settings. Its transport must support WebSocket dials.

func WithReadLimit

func WithReadLimit(limit int64) Option

WithReadLimit limits the size of each inbound text or binary message. A limit of -1 disables the limit; other non-positive values are rejected.

type WebSocketConnection

type WebSocketConnection struct {
	// contains filtered or unexported fields
}

WebSocketConnection implements the engine.io WebSocket interface. A single Receive or ReceiveFrame may run concurrently with Send, SendBinary and Close. Dial must follow Close before the backend can be reused for a new session.

func New

func New(options ...Option) (*WebSocketConnection, error)

New constructs a backend. Compression is disabled by default and incoming messages are limited to 4 MiB, matching the polling transport's default.

func (*WebSocketConnection) Close

func (ws *WebSocketConnection) Close() error

Close sends a normal close handshake and releases session resources. Calls after the first Close are no-ops. The handshake is bounded by the upstream backend's write/read timeouts (up to 5 seconds each for an unresponsive peer).

func (*WebSocketConnection) Dial

func (ws *WebSocketConnection) Dial(ctx context.Context, endpoint *url.URL, origin *url.URL) error

Dial connects and uses ctx for the whole session. Close can abort an in-flight dial; a connection that completes after Close is discarded instead of leaked.

func (*WebSocketConnection) Receive

func (ws *WebSocketConnection) Receive(v *[]byte) error

Receive reads the next message, preserving its bytes regardless of frame type.

func (*WebSocketConnection) ReceiveFrame

func (ws *WebSocketConnection) ReceiveFrame(v *[]byte) (bool, error)

ReceiveFrame reads a text or binary message and preserves the frame type for engine.io binary attachments. It also processes WebSocket ping/pong frames.

func (*WebSocketConnection) Send

func (ws *WebSocketConnection) Send(v []byte) error

Send writes an engine.io text frame.

func (*WebSocketConnection) SendBinary

func (ws *WebSocketConnection) SendBinary(v []byte) error

SendBinary writes a binary attachment without converting it to text.

Jump to

Keyboard shortcuts

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