websocket

package
v0.0.0-...-31a32bb Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 11 Imported by: 0

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. https://datatracker.ietf.org/doc/html/rfc6455#section-11.8 https://datatracker.ietf.org/doc/html/rfc6455#section-5.5 note: 1) 3-7 are reserved for further non-control frames. 2) 11-16 are reserved for further control frames.

Variables

View Source
var (
	ErrMessageClose   = errors.New("got client's close message")
	ErrMessageMaxRead = errors.New("continuation frame max read")
)
View Source
var (

	// ErrBadRequestMethod bad request method
	ErrBadRequestMethod = errors.New("bad method")
	// ErrNotWebSocket not websocket protocol
	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(closer io.ReadWriteCloser, rr *bufio.Reader, wr *bufio.Writer, req *Request) (conn *Conn, err error)

Upgrade Switching Protocols https://datatracker.ietf.org/doc/html/rfc6455#section-1.3

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Flush

func (c *Conn) Flush() error

Flush flush writer buffer

func (*Conn) Peek

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

Peek 返回n字节空间,并推进位移

func (*Conn) ReadMessage

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

ReadMessage 读取整个消息

func (*Conn) WriteHeader

func (c *Conn) WriteHeader(opcode int, length int) error

WriteHeader write header frame.

func (*Conn) WritePayload

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

WritePayload write payload

type Request

type Request struct {
	Method     string
	RequestURI string
	Proto      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 reader

func (*Request) ReadMIMEHeader

func (r *Request) ReadMIMEHeader() (header http.Header, err error)

ReadMIMEHeader read MIME header

Directories

Path Synopsis
docs

Jump to

Keyboard shortcuts

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