websocket

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 10 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

Index

Constants

View Source
const (
	// TextMessage denotes a text data message. The text message payload is
	// interpreted as UTF-8 encoded text data.
	TextMessage = 1

	// BinaryMessage denotes a binary data message.
	BinaryMessage = 2

	// CloseMessage denotes a close control message. The optional message
	// payload contains a numeric code and text. Use the FormatCloseMessage
	// function to format a close message payload.
	CloseMessage = 8

	// PingMessage denotes a ping control message. The optional message payload
	// is UTF-8 encoded text.
	PingMessage = 9

	// PongMessage denotes a ping control message. The optional message payload
	// is UTF-8 encoded text.
	PongMessage = 10
)

The message types are defined in RFC 6455, section 11.8.

Variables

View Source
var (
	// ErrMessageClose close control message
	ErrMessageClose = errors.New("close control message")
	// ErrMessageMaxRead continuation frame max read
	ErrMessageMaxRead = errors.New("continuation frame max read")
)
View Source
var (

	// ErrBadRequestMethod bad request method
	ErrBadRequestMethod = errors.New("bad method")
	// ErrNotWebSocket not websocket protocal
	ErrNotWebSocket = errors.New("not websocket protocol")
	// ErrBadWebSocketVersion bad websocket version
	ErrBadWebSocketVersion = errors.New("missing or bad WebSocket Version")
	// ErrChallengeResponse mismatch challenge response
	ErrChallengeResponse = errors.New("mismatch challenge/response")
)

Functions

This section is empty.

Types

type Conn

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

Conn represents a WebSocket connection.

func Upgrade

func Upgrade(rwc io.ReadWriteCloser, rr *bufio.Reader, wr *bufio.Writer, req *Request) (conn *Conn, err error)

Upgrade Switching Protocols

func (*Conn) Close

func (c *Conn) Close() error

Close close the connection.

func (*Conn) Flush

func (c *Conn) Flush() error

Flush flush writer buffer

func (*Conn) Peek

func (c *Conn) Peek(n int) ([]byte, error)

Peek write peek.

func (*Conn) ReadMessage

func (c *Conn) ReadMessage() (op int, payload []byte, err error)

ReadMessage read a message.

func (*Conn) WriteBody

func (c *Conn) WriteBody(b []byte) (err error)

WriteBody write a message body.

func (*Conn) WriteHeader

func (c *Conn) WriteHeader(msgType int, length int) (err error)

WriteHeader write header frame.

func (*Conn) WriteMessage

func (c *Conn) WriteMessage(msgType int, msg []byte) (err error)

WriteMessage write a message by type.

type Request

type Request struct {
	Method     string
	RequestURI string
	Proto      string
	Host       string
	Header     http.Header
	// contains filtered or unexported fields
}

Request request.

func ReadRequest

func ReadRequest(r *bufio.Reader) (req *Request, err error)

ReadRequest reads and parses an incoming request from b.

Jump to

Keyboard shortcuts

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