websocket

package
v1.2.84 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CloseNormalClosure           = 1000
	CloseGoingAway               = 1001
	CloseProtocolError           = 1002
	CloseUnsupportedData         = 1003
	CloseNoStatusReceived        = 1005
	CloseAbnormalClosure         = 1006
	CloseInvalidFramePayloadData = 1007
	ClosePolicyViolation         = 1008
	CloseMessageTooBig           = 1009
	CloseMandatoryExtension      = 1010
	CloseInternalServerErr       = 1011
	CloseServiceRestart          = 1012
	CloseTryAgainLater           = 1013
	CloseTLSHandshake            = 1015
)
View Source
const (
	TextMessage   = 1
	BinaryMessage = 2
	CloseMessage  = 8
	PingMessage   = 9
	PongMessage   = 10
)

Variables

View Source
var (
	ErrNilConn      = errors.Warning("websocket: nil *Conn")
	ErrNilNetConn   = errors.Warning("websocket: nil net.Conn")
	ErrCloseSent    = errors.Warning("websocket: close sent")
	ErrReadLimit    = errors.Warning("websocket: read limit exceeded")
	ErrBadHandshake = errors.Warning("websocket: bad handshake")
)
View Source
var DefaultDialer = &Dialer{
	Proxy:            http.ProxyFromEnvironment,
	HandshakeTimeout: 45 * time.Second,
}

Functions

func FormatCloseMessage

func FormatCloseMessage(closeCode int, text string) []byte

func IsCloseError

func IsCloseError(err error, codes ...int) bool

func IsUnexpectedCloseError

func IsUnexpectedCloseError(err error, expectedCodes ...int) bool

func IsWebSocketUpgrade

func IsWebSocketUpgrade(header transports.Header) bool

Types

type BufferPool

type BufferPool interface {
	Get() interface{}
	Put(interface{})
}

type CloseError

type CloseError struct {
	Code int
	Text string
}

func (*CloseError) Error

func (e *CloseError) Error() string

type Conn

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

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) CloseHandler

func (c *Conn) CloseHandler() func(code int, text string) error

func (*Conn) EnableWriteCompression

func (c *Conn) EnableWriteCompression(enable bool)

func (*Conn) Id

func (c *Conn) Id() []byte

func (*Conn) LocalAddr

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

func (*Conn) NetConn

func (c *Conn) NetConn() net.Conn

func (*Conn) NextReader

func (c *Conn) NextReader() (messageType int, r io.Reader, err error)

func (*Conn) NextWriter

func (c *Conn) NextWriter(messageType int) (io.WriteCloser, error)

func (*Conn) PingHandler

func (c *Conn) PingHandler() func(appData []byte) error

func (*Conn) PongHandler

func (c *Conn) PongHandler() func(appData []byte) error

func (*Conn) ReadMessage

func (c *Conn) ReadMessage() (messageType int, p []byte, err error)

func (*Conn) RemoteAddr

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

func (*Conn) SetCloseHandler

func (c *Conn) SetCloseHandler(h func(code int, text string) error)

func (*Conn) SetCompressionLevel

func (c *Conn) SetCompressionLevel(level int) error

func (*Conn) SetPingHandler

func (c *Conn) SetPingHandler(h func(appData []byte) error)

func (*Conn) SetPongHandler

func (c *Conn) SetPongHandler(h func(appData []byte) error)

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetReadLimit

func (c *Conn) SetReadLimit(limit int64)

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) Subprotocol

func (c *Conn) Subprotocol() string

func (*Conn) WriteControl

func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) error

func (*Conn) WriteJSON

func (c *Conn) WriteJSON(v interface{}) error

func (*Conn) WriteMessage

func (c *Conn) WriteMessage(messageType int, data []byte) error

func (*Conn) WritePreparedMessage

func (c *Conn) WritePreparedMessage(pm *PreparedMessage) error

func (*Conn) WriteText

func (c *Conn) WriteText(p []byte) error

type Dialer

type Dialer struct {
	NetDial           func(network, addr string) (net.Conn, error)
	NetDialContext    func(ctx context.Context, network, addr string) (net.Conn, error)
	NetDialTLSContext func(ctx context.Context, network, addr string) (net.Conn, error)
	Proxy             func(*http.Request) (*url.URL, error)
	TLSClientConfig   *tls.Config
	HandshakeTimeout  time.Duration
	ReadBufferSize    int
	WriteBufferSize   int
	WriteBufferPool   BufferPool
	Subprotocols      []string
	EnableCompression bool
	Jar               http.CookieJar
}

func (*Dialer) Dial

func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Response, error)

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader http.Header) (*Conn, *http.Response, error)

type Handler

type Handler func(ctx context.Context, conn *Conn, header transports.Header)

type HandshakeError

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

func (HandshakeError) Error

func (e HandshakeError) Error() string

type PreparedMessage

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

func NewPreparedMessage

func NewPreparedMessage(messageType int, data []byte) (*PreparedMessage, error)

type Upgrader

type Upgrader struct {
	HandshakeTimeout  time.Duration
	ReadBufferSize    int
	WriteBufferSize   int
	WriteBufferPool   BufferPool
	Subprotocols      []string
	Error             func(w transports.ResponseWriter, r transports.Request, status int, reason error)
	CheckOrigin       func(r transports.Request) bool
	EnableCompression bool
}

func (*Upgrader) Upgrade

func (u *Upgrader) Upgrade(w transports.ResponseWriter, r transports.Request, handler Handler) error

Jump to

Keyboard shortcuts

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