Documentation
¶
Overview ¶
Package ws_coder provides an optional WebSocket backend with compression, message size limits and RFC 6455 close handshakes.
Index ¶
- Variables
- type Option
- type WebSocketConnection
- func (ws *WebSocketConnection) Close() error
- func (ws *WebSocketConnection) Dial(ctx context.Context, endpoint *url.URL, origin *url.URL) error
- func (ws *WebSocketConnection) Receive(v *[]byte) error
- func (ws *WebSocketConnection) ReceiveFrame(v *[]byte) (bool, error)
- func (ws *WebSocketConnection) Send(v []byte) error
- func (ws *WebSocketConnection) SendBinary(v []byte) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
WithHTTPClient uses client for the HTTP upgrade request, allowing custom TLS, proxy, cookie and timeout settings. Its transport must support WebSocket dials.
func WithReadLimit ¶
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 ¶
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.