websocket

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2019 License: CC0-1.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Subprotocols   []string
	MaxMessageSize int
}

Settings for potential WebSocket connections. Subprotocols is a list of supported subprotocols as in RFC 6455 section 1.9. When answering client requests, the first of the client's requests subprotocols that is also in this list (if any) will be used as the subprotocol for the connection. MaxMessageSize is a limit on buffering messages.

func (*Config) Handler

func (config *Config) Handler(callback func(*WebSocket)) http.Handler

Return an http.Handler with the given callback function.

type Frame

type Frame struct {
	Fin     bool
	Opcode  byte
	Payload []byte
}

Representation of a WebSocket frame. The Payload is always without masking.

func (*Frame) IsControl

func (frame *Frame) IsControl() bool

Return true iff the frame's opcode says it is a control frame.

type HTTPHandler

type HTTPHandler struct {
	Config   *Config
	Callback func(*WebSocket)
}

An implementation of http.Handler with a Config. The ServeHTTP function calls Callback assuming WebSocket HTTP negotiation is successful.

func (*HTTPHandler) ServeHTTP

func (handler *HTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

Implements the http.Handler interface.

type Message

type Message struct {
	Opcode  byte
	Payload []byte
}

Representation of a WebSocket message. The Payload is always without masking.

type WebSocket

type WebSocket struct {
	// Conn and ReadWriter from http.ResponseWriter.Hijack.
	Conn  net.Conn
	Bufrw *bufio.ReadWriter
	// Whether we are a client or a server has implications for masking.
	IsClient bool
	// Set from a parent Config.
	MaxMessageSize int
	// The single selected subprotocol after negotiation, or "".
	Subprotocol string
	// contains filtered or unexported fields
}

A WebSocket connection after hijacking from HTTP.

func (*WebSocket) ReadFrame

func (ws *WebSocket) ReadFrame() (frame Frame, err error)

Read a single frame from the WebSocket.

func (*WebSocket) ReadMessage

func (ws *WebSocket) ReadMessage() (message Message, err error)

Read a single message from the WebSocket. Multiple fragmented frames are combined into a single message before being returned. Non-control messages may be interrupted by control frames. The control frames are returned as individual messages before the message that they interrupt.

func (*WebSocket) Request

func (ws *WebSocket) Request() *http.Request

func (*WebSocket) WriteFrame

func (ws *WebSocket) WriteFrame(opcode byte, payload []byte) (err error)

Write a single frame to the WebSocket stream. Destructively masks payload in place if ws.IsClient. Frames are always unfragmented.

func (*WebSocket) WriteMessage

func (ws *WebSocket) WriteMessage(opcode byte, payload []byte) (err error)

Write a single message to the WebSocket stream. Destructively masks payload in place if ws.IsClient. Messages are always sent as a single unfragmented frame.

Jump to

Keyboard shortcuts

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