ws

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package ws is a minimal, dependency-free RFC 6455 WebSocket server implementation, sufficient to carry Engine.IO/Socket.IO traffic. It supports the server-side opening handshake, fragmented data messages, and the control frames (ping/pong/close). Only what Socket.IO needs is implemented; it is not a general-purpose WebSocket library.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("ws: connection closed")

ErrClosed is returned once the connection has been closed.

Functions

func IsWebSocketUpgrade

func IsWebSocketUpgrade(r *http.Request) bool

IsWebSocketUpgrade reports whether r is a WebSocket upgrade request.

Types

type Conn

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

Conn is a WebSocket connection (server- or client-side).

func Dial

func Dial(rawURL string, header http.Header) (*Conn, error)

Dial opens a client WebSocket connection to a ws:// or http:// URL. The returned Conn masks outgoing frames as required for clients.

func Upgrade

func Upgrade(w http.ResponseWriter, r *http.Request) (*Conn, error)

Upgrade completes the server handshake and hijacks the connection, returning a *Conn ready for ReadMessage/WriteMessage.

func (*Conn) Close

func (c *Conn) Close() error

Close sends a close frame and tears down the connection.

func (*Conn) ReadMessage

func (c *Conn) ReadMessage() (MessageType, []byte, error)

ReadMessage reads the next data message, transparently answering ping and close control frames. It reassembles fragmented messages.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns the underlying connection's remote address.

func (*Conn) WriteMessage

func (c *Conn) WriteMessage(t MessageType, data []byte) error

WriteMessage writes a complete data message (single, unmasked frame).

func (*Conn) WriteText

func (c *Conn) WriteText(s string) error

WriteText is a convenience for sending a text message.

type MessageType

type MessageType int

MessageType distinguishes text and binary data messages.

const (
	// TextMessage is a UTF-8 text message.
	TextMessage MessageType = iota
	// BinaryMessage is a binary message.
	BinaryMessage
)

Jump to

Keyboard shortcuts

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