websocket

package
v1.0.0-rc8 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATUS_CLOSE_NORMAL_CLOSURE        = 1000
	STATUS_CLOSE_GOING_AWAY            = 1001
	STATUS_CLOSE_PROTOCOL_ERR          = 1002
	STATUS_CLOSE_UNSUPPORTED           = 1003
	STATUS_CLOSE_NO_STATUS             = 1005
	STATUS_CLOSE_ABNORMAL_CLOSURE      = 1006
	STATUS_CLOSE_INVALID_PAYLOAD       = 1007
	STATUS_CLOSE_POLICY_VIOLATION      = 1008
	STATUS_CLOSE_MESSAGE_TOO_BIG       = 1009
	STATUS_CLOSE_MANDATORY_EXTENSION   = 1010
	STATUS_CLOSE_INTERNAL_SERVER_ERROR = 1011
	STATUS_CLOSE_SERVICE_RESTART       = 1012
	STATUS_CLOSE_TRY_AGAIN_LATER       = 1013
	STATUS_CLOSE_TLS_HANDSHAKE         = 1015
)

status codes for websocket close frames

View Source
const MAGIC_KEY = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"

Variables

This section is empty.

Functions

func EncodeFrame

func EncodeFrame(payload []byte, opcode Opcode) ([]byte, error)

EncodeFrame encodes a WebSocket frame with the given payload and opcode.

Types

type Client

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

Client represents a WebSocket client connection.

func (*Client) Close

func (ws *Client) Close(reason []byte, code int) error

Close closes the WebSocket connection with a reason and code.

func (*Client) Read

func (ws *Client) Read(data []byte) (Frame, int, error)

Read reads a WebSocket frame from the connection.

func (*Client) Write

func (ws *Client) Write(data []byte, opcode Opcode) (int, error)

Write writes a WebSocket frame to the connection with the specified opcode.

type Frame

type Frame struct {
	FIN           bool
	RSV1          bool
	RSV2          bool
	RSV3          bool
	OpCode        Opcode
	IsMasked      bool
	MaskingKey    [4]byte
	PayloadLength uint64
	Payload       []byte
}

Frame represents a WebSocket frame.

func DecodeFrame

func DecodeFrame(data []byte) (Frame, error)

DecodeFrame decodes a WebSocket frame from the given byte slice.

type Opcode

type Opcode byte
const (
	CONTINUATION Opcode = 0x0
	TEXT         Opcode = 0x1
	BINARY       Opcode = 0x2
	CLOSE        Opcode = 0x8
	PING         Opcode = 0x9
	PONG         Opcode = 0xA
)

opcode

type Websocket

type Websocket struct{}

func (*Websocket) Upgrade

func (ws *Websocket) Upgrade(w http.ResponseWriter, r *http.Request) (*Client, error)

Upgrade upgrades an HTTP connection to a WebSocket connection.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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